calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject incubator-calcite git commit: [CALCITE-566] ReduceExpressionsRule requires planner to have an Executor
Date Fri, 06 Mar 2015 07:45:04 GMT
Repository: incubator-calcite
Updated Branches:
  refs/heads/master b659d0f3b -> 49ec28018


[CALCITE-566] ReduceExpressionsRule requires planner to have an Executor

Also fix some code style issues


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

Branch: refs/heads/master
Commit: 49ec280180cfa74cb35f6a50fbcf84857f690951
Parents: b659d0f
Author: Julian Hyde <jhyde@apache.org>
Authored: Tue Mar 3 20:59:08 2015 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Tue Mar 3 20:59:08 2015 -0800

----------------------------------------------------------------------
 .../calcite/rel/rules/ReduceExpressionsRule.java | 12 +++++++++++-
 .../apache/calcite/sql/parser/SqlParserTest.java |  3 ++-
 .../org/apache/calcite/test/RelOptRulesTest.java | 17 +++++++++++++++++
 .../calcite/test/SqlToRelConverterTest.java      | 16 +++++++++++-----
 .../apache/calcite/test/SqlValidatorTest.java    |  3 ++-
 .../org/apache/calcite/test/RelOptRulesTest.xml  | 19 +++++++++++++++++++
 6 files changed, 62 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/49ec2801/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 01b05f7..8bcf4b2 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
@@ -153,7 +153,6 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
           // If the expression is a IS [NOT] NULL on a non-nullable
           // column, then we can either remove the filter or replace
           // it with an Empty.
-          SqlOperator op = rexCall.getOperator();
           boolean alwaysTrue;
           switch (rexCall.getKind()) {
           case IS_NULL:
@@ -386,6 +385,17 @@ public abstract class ReduceExpressionsRule extends RelOptRule {
     // Compute the values they reduce to.
     RelOptPlanner.Executor executor =
         rel.getCluster().getPlanner().getExecutor();
+    if (executor == null) {
+      // Cannot reduce expressions: caller has not set an executor in their
+      // environment. Caller should execute something like the following before
+      // invoking the planner:
+      //
+      // final RexExecutorImpl executor =
+      //   new RexExecutorImpl(Schemas.createDataContext(null));
+      // rootRel.getCluster().getPlanner().setExecutor(executor);
+      return false;
+    }
+
     final List<RexNode> reducedValues = Lists.newArrayList();
     executor.reduce(rexBuilder, constExps2, reducedValues);
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/49ec2801/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 48eb1d5..70eb39c 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -825,7 +825,8 @@ public class SqlParserTest {
   @Test public void testGroupByRollup() {
     sql("select deptno from emp\n"
         + "group by rollup (deptno, deptno + 1, gender)")
-        .ok("SELECT `DEPTNO`\n" + "FROM `EMP`\n"
+        .ok("SELECT `DEPTNO`\n"
+            + "FROM `EMP`\n"
             + "GROUP BY (ROLLUP(`DEPTNO`, (`DEPTNO` + 1), `GENDER`))");
 
     // Nested rollup not ok

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/49ec2801/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 fdc0779..bb70d37 100644
--- a/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelOptRulesTest.java
@@ -662,6 +662,23 @@ public class RelOptRulesTest extends RelOptTestBase {
         "select * from (values (1,2)) where 1 + 2 > 3 + CAST(NULL AS INTEGER)");
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-566">[CALCITE-566],
+   * ReduceExpressionsRule requires planner to have an Executor</a>. */
+  @Test public void testReduceConstantsRequiresExecutor() throws Exception {
+    HepProgram program = new HepProgramBuilder()
+        .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)
+        .build();
+
+    // Remove the executor
+    tester.convertSqlToRel("values 1").getCluster().getPlanner()
+        .setExecutor(null);
+
+    // Rule should not fire, but there should be no NPE
+    checkPlanning(program,
+        "select * from (values (1,2)) where 1 + 2 > 3 + CAST(NULL AS INTEGER)");
+  }
+
   @Test public void testAlreadyFalseEliminatesFilter() throws Exception {
     HepProgram program = new HepProgramBuilder()
         .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE)

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/49ec2801/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index ad6c13a..0d35faf 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1043,13 +1043,19 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
     rel.explain(planWriter);
     pw.flush();
     TestUtil.assertEqualsVerbose(
-        "<RelNode type=\"LogicalProject\">\n" + "\t<Property name=\"EXPR$0\">\n"
-            + "\t\t+(1, 2)\t</Property>\n" + "\t<Property name=\"EXPR$1\">\n"
-            + "\t\t3\t</Property>\n" + "\t<Inputs>\n"
+        "<RelNode type=\"LogicalProject\">\n"
+            + "\t<Property name=\"EXPR$0\">\n"
+            + "\t\t+(1, 2)\t</Property>\n"
+            + "\t<Property name=\"EXPR$1\">\n"
+            + "\t\t3\t</Property>\n"
+            + "\t<Inputs>\n"
             + "\t\t<RelNode type=\"LogicalValues\">\n"
             + "\t\t\t<Property name=\"tuples\">\n"
-            + "\t\t\t\t[{ true }]\t\t\t</Property>\n" + "\t\t\t<Inputs/>\n"
-            + "\t\t</RelNode>\n" + "\t</Inputs>\n" + "</RelNode>\n",
+            + "\t\t\t\t[{ true }]\t\t\t</Property>\n"
+            + "\t\t\t<Inputs/>\n"
+            + "\t\t</RelNode>\n"
+            + "\t</Inputs>\n"
+            + "</RelNode>\n",
         Util.toLinux(sw.toString()));
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/49ec2801/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 8a4cbc3..d569d94 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -5333,7 +5333,8 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
 
     // self-reference is not ok, even in table not used
     checkFails("with emp2 as (select * from emp),\n"
-            + " emp3 as (select * from ^emp3^)\n" + "values (1)",
+            + " emp3 as (select * from ^emp3^)\n"
+            + "values (1)",
         "Table 'EMP3' not found");
 
     // self-reference not ok

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/49ec2801/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 e305849..60bd03e 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -3340,4 +3340,23 @@ LogicalProject(DEPTNO=[$0], ENAME=[$1])
 ]]>
         </Resource>
     </TestCase>
+    <TestCase name="testReduceConstantsRequiresExecutor">
+        <Resource name="sql">
+            <![CDATA[select * from (values (1,2)) where 1 + 2 > 3 + CAST(NULL AS INTEGER)]]>
+        </Resource>
+        <Resource name="planBefore">
+            <![CDATA[
+LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
+  LogicalFilter(condition=[>(+(1, 2), +(3, null))])
+    LogicalValues(tuples=[[{ 1, 2 }]])
+]]>
+        </Resource>
+        <Resource name="planAfter">
+            <![CDATA[
+LogicalProject(EXPR$0=[$0], EXPR$1=[$1])
+  LogicalFilter(condition=[>(+(1, 2), +(3, null))])
+    LogicalValues(tuples=[[{ 1, 2 }]])
+]]>
+        </Resource>
+    </TestCase>
 </Root>


Mime
View raw message