You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ma...@apache.org on 2015/11/23 21:16:39 UTC

calcite git commit: [CALCITE-988] FilterToProjectUnifyRule.invert(MutableRel, MutableRel, MutableProject) works incorrectly

Repository: calcite
Updated Branches:
  refs/heads/master 3e7efce6e -> f15566615


[CALCITE-988] FilterToProjectUnifyRule.invert(MutableRel, MutableRel, MutableProject) works incorrectly


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

Branch: refs/heads/master
Commit: f155666156c26fa43e4191af43ad99a779aad5b0
Parents: 3e7efce
Author: maryannxue <we...@intel.com>
Authored: Mon Nov 23 15:16:14 2015 -0500
Committer: maryannxue <we...@intel.com>
Committed: Mon Nov 23 15:16:14 2015 -0500

----------------------------------------------------------------------
 .../calcite/plan/SubstitutionVisitor.java       |  4 +-
 .../calcite/test/MaterializationTest.java       | 52 ++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/f1556661/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
index 739c6ba..924529c 100644
--- a/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
+++ b/core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
@@ -1150,9 +1150,9 @@ public class SubstitutionVisitor {
       for (Ord<RexNode> expr : Ord.zip(project.getProjects())) {
         if (expr.e instanceof RexInputRef) {
           final int target = ((RexInputRef) expr.e).getIndex();
-          exprList.set(expr.i,
+          exprList.set(target,
               rexBuilder.ensureType(expr.e.getType(),
-                  RexInputRef.of(target, input.rowType),
+                  RexInputRef.of(expr.i, input.rowType),
                   false));
         } else {
           throw MatchFailed.INSTANCE;

http://git-wip-us.apache.org/repos/asf/calcite/blob/f1556661/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
index 87b72bc..9f327cc 100644
--- a/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
+++ b/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
@@ -257,6 +257,58 @@ public class MaterializationTest {
         JdbcTest.HR_MODEL);
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-988">[CALCITE-988]
+   * FilterToProjectUnifyRule.invert(MutableRel, MutableRel, MutableProject)
+   * works incorrectly</a>. */
+  @Test public void testFilterQueryOnProjectView8() {
+    try {
+      Prepare.THREAD_TRIM.set(true);
+      MaterializationService.setThreadLocal();
+      final String m = "select \"salary\", \"commission\",\n"
+          + "\"deptno\", \"empid\", \"name\" from \"emps\"";
+      final String v = "select * from \"emps\" where \"salary\" is null";
+      final String q = "select * from V where \"commission\" is null";
+      final JsonBuilder builder = new JsonBuilder();
+      final String model = "{\n"
+          + "  version: '1.0',\n"
+          + "  defaultSchema: 'hr',\n"
+          + "  schemas: [\n"
+          + "    {\n"
+          + "      materializations: [\n"
+          + "        {\n"
+          + "          table: 'm0',\n"
+          + "          view: 'm0v',\n"
+          + "          sql: " + builder.toJsonString(m)
+          + "        }\n"
+          + "      ],\n"
+          + "      tables: [\n"
+          + "        {\n"
+          + "          name: 'V',\n"
+          + "          type: 'view',\n"
+          + "          sql: " + builder.toJsonString(v) + "\n"
+          + "        }\n"
+          + "      ],\n"
+          + "      type: 'custom',\n"
+          + "      name: 'hr',\n"
+          + "      factory: 'org.apache.calcite.adapter.java.ReflectiveSchema$Factory',\n"
+          + "      operand: {\n"
+          + "        class: 'org.apache.calcite.test.JdbcTest$HrSchema'\n"
+          + "      }\n"
+          + "    }\n"
+          + "  ]\n"
+          + "}\n";
+      CalciteAssert.that()
+          .withModel(model)
+          .query(q)
+          .enableMaterializations(true)
+          .explainMatches("", CONTAINS_M0)
+          .sameResultWithMaterializationsDisabled();
+    } finally {
+      Prepare.THREAD_TRIM.set(false);
+    }
+  }
+
   @Test public void testFilterQueryOnFilterView() {
     checkMaterialize(
         "select \"deptno\", \"empid\", \"name\" from \"emps\" where \"deptno\" = 10",