You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jc...@apache.org on 2018/11/19 20:39:18 UTC

calcite git commit: [CALCITE-2675] Type validation error as ReduceExpressionRule fails to preserve type nullability (Zoltan Haindrich)

Repository: calcite
Updated Branches:
  refs/heads/master 53e15af6c -> d32ee5c32


[CALCITE-2675] Type validation error as ReduceExpressionRule fails to preserve type nullability (Zoltan Haindrich)

Close apache/calcite#922


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/d32ee5c3
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/d32ee5c3
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/d32ee5c3

Branch: refs/heads/master
Commit: d32ee5c320938b5c34ce09df2276c9570c27a301
Parents: 53e15af
Author: Zoltan Haindrich <ki...@rxd.hu>
Authored: Thu Nov 15 17:42:01 2018 +0100
Committer: Jesus Camacho Rodriguez <jc...@apache.org>
Committed: Mon Nov 19 11:55:08 2018 -0800

----------------------------------------------------------------------
 .../calcite/rel/rules/ReduceExpressionsRule.java   |  3 ---
 .../org/apache/calcite/test/RelOptRulesTest.java   | 13 +++++++++++++
 .../org/apache/calcite/test/RelOptRulesTest.xml    | 17 +++++++++++++++++
 3 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/d32ee5c3/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
index 5ba3d3c..741d083 100644
--- a/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
+++ b/core/src/main/java/org/apache/calcite/rel/rules/ReduceExpressionsRule.java
@@ -790,9 +790,6 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
         return node;
       }
       node = super.visitCall(call);
-      if (node != call) {
-        node = simplify.simplifyUnknownAs(node, unknownAs);
-      }
       return node;
     }
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/d32ee5c3/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
index e3a943a..e91af51 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -2584,6 +2584,19 @@ public class RelOptRulesTest extends RelOptTestBase {
             + "where cast((empno + (10/2)) as int) = 13");
   }
 
+  @Test public <T> void testReduceCaseNullabilityChange() throws Exception {
+    HepProgram program = new HepProgramBuilder()
+        .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
+        .addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE)
+        .build();
+
+    try (Hook.Closeable a = Hook.REL_BUILDER_SIMPLIFY.add(Hook.propertyJ(false))) {
+      checkPlanning(program,
+          "select case when empno = 1 then 1 when 1 IS NOT NULL then 2 else null end as qx "
+              + "from emp");
+    }
+  }
+
   @Ignore // Calcite does not support INSERT yet
   @Test public void testReduceCastsNullable() throws Exception {
     HepProgram program = new HepProgramBuilder()

http://git-wip-us.apache.org/repos/asf/calcite/blob/d32ee5c3/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index a702384..7d90b75 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -6183,6 +6183,23 @@ LogicalProject(EXPR$0=[CASE(=($1, 0), null, $0)])
 ]]>
         </Resource>
     </TestCase>
+    <TestCase name="testReduceCaseNullabilityChange">
+        <Resource name="sql">
+            <![CDATA[select case when empno = 1 then 1 when 1 IS NOT NULL then 2 else null end as qx from emp]]>
+        </Resource>
+        <Resource name="planBefore">
+            <![CDATA[
+LogicalProject(QX=[CASE(=($0, 1), 1, IS NOT NULL(1), 2, null)])
+  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+        <Resource name="planAfter">
+            <![CDATA[
+LogicalProject(QX=[CAST(CASE(=($0, 1), 1, 2)):INTEGER])
+  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
     <TestCase name="testReduceConstantsDynamicFunction">
         <Resource name="sql">
             <![CDATA[select sal, t