You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2015/07/14 02:24:53 UTC

incubator-calcite git commit: [CALCITE-774] When GROUP BY is present, ensure that window function operands only refer to GROUP BY keys (Hsuan-Yi Chu)

Repository: incubator-calcite
Updated Branches:
  refs/heads/master 92f32e8d5 -> e51f853f3


[CALCITE-774] When GROUP BY is present, ensure that window function operands only refer to GROUP BY keys (Hsuan-Yi Chu)

Close apache/incubator-calcite#101


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

Branch: refs/heads/master
Commit: e51f853f3461a4e3f0a74b8d83cfc01e39b3f5db
Parents: 92f32e8
Author: Hsuan-Yi Chu <hs...@usc.edu>
Authored: Fri Jun 26 08:42:46 2015 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Mon Jul 13 15:48:31 2015 -0700

----------------------------------------------------------------------
 .../org/apache/calcite/sql/validate/AggChecker.java   |  7 +++++++
 .../org/apache/calcite/test/SqlValidatorTest.java     | 14 ++++++++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/e51f853f/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java b/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
index f8c2776..39a7f3c 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/AggChecker.java
@@ -148,6 +148,13 @@ class AggChecker extends SqlBasicVisitor<Void> {
       call.operand(0).accept(this);
       return null;
     }
+    // Visit the operand in window function
+    if (call.getOperator().getKind() == SqlKind.OVER) {
+      SqlCall windowFunction = (SqlCall) call.operand(0);
+      if (windowFunction.getOperandList().size() != 0) {
+        windowFunction.operand(0).accept(this);
+      }
+    }
     if (isGroupExpr(call)) {
       // This call matches an expression in the GROUP BY clause.
       return null;

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/e51f853f/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 811343b..cc8153e 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -3986,6 +3986,20 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
             "RANK or DENSE_RANK functions require ORDER BY clause in window specification");
   }
 
+  @Test public void testInvalidWindowFunctionWithGroupBy() {
+    sql("select max(^empno^) over () from emp\n"
+        + "group by deptno")
+        .fails("Expression 'EMPNO' is not being grouped");
+
+    sql("select max(deptno) over (partition by ^empno^) from emp\n"
+        + "group by deptno")
+        .fails("Expression 'EMPNO' is not being grouped");
+
+    sql("select rank() over (order by ^empno^) from emp\n"
+        + "group by deptno")
+        .fails("Expression 'EMPNO' is not being grouped");
+  }
+
   @Test public void testInlineWinDef() {
     // the <window specification> used by windowed agg functions is
     // fully defined in SQL 03 Std. section 7.1 <window clause>