calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [21/50] [abbrv] incubator-calcite git commit: [CALCITE-710] Identical conditions in the WHERE clause cause assertion error (Sean Hsuan-Yi Chu)
Date Fri, 31 Jul 2015 22:42:58 GMT
[CALCITE-710] Identical conditions in the WHERE clause cause assertion error (Sean Hsuan-Yi
Chu)

When look up subqueries, perform the same logic as the way when ones were registered.

Close apache/incubator-calcite#82


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

Branch: refs/heads/branch-release
Commit: af01c5afa849f38e8148130afcdf8e911575d7bd
Parents: f076a9b
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Mon May 4 15:00:46 2015 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Tue May 5 14:41:38 2015 -0700

----------------------------------------------------------------------
 .../calcite/sql2rel/SqlToRelConverter.java      | 26 +++++++++++---------
 .../calcite/test/SqlToRelConverterTest.java     | 12 +++++++++
 .../calcite/test/SqlToRelConverterTest.xml      | 14 +++++++++++
 3 files changed, 40 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/af01c5af/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 905578d..88213e6 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -184,12 +184,6 @@ public class SqlToRelConverter {
   protected static final Logger SQL2REL_LOGGER =
       CalciteTrace.getSqlToRelTracer();
 
-  private static final Function<SubQuery, SqlNode> FN =
-      new Function<SubQuery, SqlNode>() {
-        public SqlNode apply(SubQuery input) {
-          return input.node;
-        }
-      };
   private static final BigDecimal TWO = BigDecimal.valueOf(2L);
 
   //~ Instance fields --------------------------------------------------------
@@ -3712,9 +3706,6 @@ public class SqlToRelConverter {
      */
     private final Set<SubQuery> subqueryList = Sets.newLinkedHashSet();
 
-    private final Map<SqlNode, SubQuery> subqueryMap =
-        Util.asIndexMap(subqueryList, FN);
-
     private boolean subqueryNeedsOuterJoin;
 
     /**
@@ -4040,6 +4031,16 @@ public class SqlToRelConverter {
       subqueryList.add(new SubQuery(node, logic));
     }
 
+    SubQuery getSubquery(SqlNode expr) {
+      for (SubQuery subQuery : subqueryList) {
+        if (expr.equalsDeep(subQuery.node, false)) {
+          return subQuery;
+        }
+      }
+
+      return null;
+    }
+
     ImmutableList<RelNode> retrieveCursors() {
       try {
         return ImmutableList.copyOf(cursors);
@@ -4079,7 +4080,8 @@ public class SqlToRelConverter {
       switch (kind) {
       case CURSOR:
       case IN:
-        subQuery = subqueryMap.get(expr);
+        subQuery = getSubquery(expr);
+
         assert subQuery != null;
         rex = subQuery.expr;
         assert rex != null : "rex != null";
@@ -4088,7 +4090,7 @@ public class SqlToRelConverter {
       case SELECT:
       case EXISTS:
       case SCALAR_QUERY:
-        subQuery = subqueryMap.get(expr);
+        subQuery = getSubquery(expr);
         assert subQuery != null;
         rex = subQuery.expr;
         assert rex != null : "rex != null";
@@ -4192,7 +4194,7 @@ public class SqlToRelConverter {
 
     // implement SqlRexContext
     public RexRangeRef getSubqueryExpr(SqlCall call) {
-      final SubQuery subQuery = subqueryMap.get(call);
+      final SubQuery subQuery = getSubquery(call);
       assert subQuery != null;
       return (RexRangeRef) subQuery.expr;
     }

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/af01c5af/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 fd09a21..5adba1d 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1180,6 +1180,18 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
   }
 
   /**
+   * Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-710">[CALCITE-710]
+   * When look up subqueries, perform the same logic as the way when ones were registered</a>.
+   */
+  @Test public void testIdenticalExpressionInSubquery() {
+    sql("select deptno\n"
+        + "from EMP\n"
+        + "where deptno in (1, 2) or deptno in (1, 2)")
+        .convertsTo("${plan}");
+  }
+
+  /**
    * Visitor that checks that every {@link RelNode} in a tree is valid.
    *
    * @see RelNode#isValid(boolean)

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/af01c5af/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
----------------------------------------------------------------------
diff --git a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index 76070dc..15accd9 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -2475,4 +2475,18 @@ LogicalProject(DEPTNO=[$7])
 ]]>
         </Resource>
     </TestCase>
+    <TestCase name="testIdenticalExpressionInSubquery">
+        <Resource name="sql">
+            <![CDATA[select deptno
+from EMP
+where deptno in (1, 2) or deptno in (1, 2)]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+LogicalProject(DEPTNO=[$7])
+  LogicalFilter(condition=[OR(=($7, 1), =($7, 2), =($7, 1), =($7, 2))])
+    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
 </Root>


Mime
View raw message