You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jn...@apache.org on 2016/08/08 21:11:37 UTC

calcite git commit: [CALCITE-1346] Invalid nested window aggregates query with alias (AS clause) should fail validation

Repository: calcite
Updated Branches:
  refs/heads/master 0c91411a5 -> fd4f85e67


[CALCITE-1346] Invalid nested window aggregates query with alias (AS clause) should fail validation

Close apache/calcite#267


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

Branch: refs/heads/master
Commit: fd4f85e6738c8165d4ea96499195612ba3226f59
Parents: 0c91411
Author: Gautam Parai <gp...@maprtech.com>
Authored: Fri Aug 5 15:02:22 2016 -0700
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Mon Aug 8 13:55:15 2016 -0700

----------------------------------------------------------------------
 .../calcite/sql/validate/SqlValidatorImpl.java  |  5 +++--
 .../apache/calcite/test/SqlValidatorTest.java   | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/fd4f85e6/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 4caa1ef..21df5d7 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
@@ -2509,8 +2509,9 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     // Also when nested window aggregates are present
     for (SqlNode node : select.getSelectList()) {
       if (node instanceof SqlCall) {
-        SqlCall call = (SqlCall) node;
-        if (call.getOperator().getKind() == SqlKind.OVER
+        SqlCall call = (SqlCall) overFinder.findAgg(node);
+        if (call != null
+            && call.getOperator().getKind() == SqlKind.OVER
             && call.getOperandList().size() != 0) {
           if (call.operand(0) instanceof SqlCall
               && isNestedAggregateWindow((SqlCall) call.operand(0))) {

http://git-wip-us.apache.org/repos/asf/calcite/blob/fd4f85e6/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 c6c22e9..c5b47c3 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -6443,6 +6443,26 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
         + " count(empno + deptno) OVER (partition by empno + deptno + 1)\n"
         + " from emp group by empno + deptno");
 
+    // expression is NOT OK (AS clause)
+    sql("select sum(max(empno))\n"
+        + " OVER (order by ^deptno^ ROWS 2 PRECEDING) AS sumEmpNo\n"
+        + " from emp")
+        .fails("Expression 'DEPTNO' is not being grouped");
+    sql("select sum(max(empno)) OVER w AS sumEmpNo\n"
+        + " from emp\n"
+        + " window w AS (order by ^deptno^ ROWS 2 PRECEDING)")
+        .fails("Expression 'DEPTNO' is not being grouped");
+    sql("select avg(^sal^) OVER () AS avgSal,"
+        + " avg(count(empno)) OVER (partition by 1) AS avgEmpNo\n"
+        + " from emp")
+        .fails("Expression 'SAL' is not being grouped");
+    sql("select count(deptno, deptno + 1, ^empno^) OVER () AS cntDeptEmp\n"
+        + " from emp group by deptno")
+        .fails("Expression 'EMPNO' is not being grouped");
+    sql("select avg(sum(sal)) OVER (partition by ^deptno^ + 1) AS avgSal\n"
+        + "from emp group by empno + deptno")
+        .fails("Expression 'DEPTNO' is not being grouped");
+
     // OVER in clause
     checkFails(
         "select ^sum(max(empno) OVER (order by deptno ROWS 2 PRECEDING))^ from emp",