calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject calcite git commit: [CALCITE-1313] Validator should derive type of expression in ORDER BY (Minji Kim)
Date Tue, 12 Jul 2016 02:40:47 GMT
Repository: calcite
Updated Branches:
  refs/heads/master 63c51d0c6 -> b4f28d7e2


[CALCITE-1313] Validator should derive type of expression in ORDER BY (Minji Kim)

SqlValidatorImpl.expandOrderExpr should validate node type and set it.

Close apache/calcite#254


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

Branch: refs/heads/master
Commit: b4f28d7e2b79d0df9ce5e8d2ec824c84d31e9741
Parents: 63c51d0
Author: Minji Kim <minji@dremio.com>
Authored: Thu Jun 23 18:52:35 2016 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon Jul 11 17:34:35 2016 -0700

----------------------------------------------------------------------
 .../calcite/sql/validate/SqlValidatorImpl.java       | 10 +++++++++-
 .../apache/calcite/test/SqlToRelConverterTest.java   | 10 ++++++++++
 .../apache/calcite/test/SqlToRelConverterTest.xml    | 15 +++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/b4f28d7e/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 2b6b640..9e8dd6c 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -3343,7 +3343,15 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
   }
 
   public SqlNode expandOrderExpr(SqlSelect select, SqlNode orderExpr) {
-    return new OrderExpressionExpander(select, orderExpr).go();
+    final SqlNode newSqlNode =
+        new OrderExpressionExpander(select, orderExpr).go();
+    if (newSqlNode != orderExpr) {
+      final SqlValidatorScope scope = getOrderScope(select);
+      inferUnknownTypes(unknownType, scope, newSqlNode);
+      final RelDataType type = deriveType(scope, newSqlNode);
+      setValidatedNodeTypeImpl(newSqlNode, type);
+    }
+    return newSqlNode;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/calcite/blob/b4f28d7e/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 4ab1ae7..5162577 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1640,6 +1640,16 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
     sql(sql).ok();
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-1313">[CALCITE-1313]
+   * Validator should derive type of expression in ORDER BY</a>.
+   */
+  @Test public void testOrderByOver() {
+    String sql = "select deptno, rank() over(partition by empno order by deptno)\n"
+        + "from emp order by row_number() over(partition by empno order by deptno)";
+    sql(sql).ok();
+  }
+
   /**
    * Test case (correlated scalar aggregate subQuery) for
    * <a href="https://issues.apache.org/jira/browse/CALCITE-714">[CALCITE-714]

http://git-wip-us.apache.org/repos/asf/calcite/blob/b4f28d7e/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 d16b3fd..0241f7e 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -2535,6 +2535,21 @@ LogicalProject(X=[$0], Y=[$1], Z=[$2], EMPNO=[$3])
 ]]>
         </Resource>
     </TestCase>
+    <TestCase name="testOrderByOver">
+        <Resource name="sql">
+            <![CDATA[select deptno, rank() over(partition by empno order by deptno)
+   from emp order by row_number() over(partition by empno order by deptno)
+]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
+  LogicalSort(sort0=[$2], dir0=[ASC])
+    LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY $7 RANGE BETWEEN
UNBOUNDED PRECEDING AND CURRENT ROW)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY
$7 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)])
+      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
     <TestCase name="testValuesUsing">
         <Resource name="sql">
             <![CDATA[select d.deptno, min(e.empid) as empid


Mime
View raw message