Repository: calcite
Updated Branches:
  refs/heads/master 37a83b102 -> a1fe76911


[CALCITE-2081] Query with windowed aggregates under both sides of a JOIN throws 
NullPointerException (Zhen Wang)

Fixed by introducing a counter so that the two windows would have
distinct variable names in generated code. Before this fix there was
a NullPointerException during code generation.

Remove an unused constant.

Close apache/calcite#634


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

Branch: refs/heads/master
Commit: a1fe769114a15559b5f352059aec1f91f416a28b
Parents: 37a83b1
Author: zhen wang <zinki...@gmail.com>
Authored: Fri Feb 23 14:46:39 2018 +0800
Committer: Julian Hyde <jh...@apache.org>
Committed: Fri Feb 23 15:08:50 2018 -0800

----------------------------------------------------------------------
 .../enumerable/EnumerableRelImplementor.java    |  7 +-----
 .../adapter/enumerable/EnumerableWindow.java    |  5 ++--
 core/src/test/resources/sql/winagg.iq           | 26 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/a1fe7691/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
index cc86fea..dfae89f 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableRelImplementor.java
@@ -67,17 +67,12 @@ import java.util.Set;
  * operators of {@link EnumerableConvention} calling convention.
  */
 public class EnumerableRelImplementor extends JavaRelImplementor {
-  /** Maximum number of arguments to a constructor. See
-   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-1097";>[CALCITE-1097]
-   * Exception when executing query with too many aggregation columns</a> for
-   * details. */
-  private static final int MAX_CONSTRUCTOR_ARG_COUNT = 10;
-
   public final Map<String, Object> map;
   private final Map<String, RexToLixTranslator.InputGetter> corrVars =
       Maps.newHashMap();
   private final Map<Object, ParameterExpression> stashedParameters =
       Maps.newIdentityHashMap();
+  int windowCount = 0;
 
   protected final Function1<String, RexToLixTranslator.InputGetter> 
allCorrelateVariables =
       new Function1<String, RexToLixTranslator.InputGetter>() {

http://git-wip-us.apache.org/repos/asf/calcite/blob/a1fe7691/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
index 0e32225..9c7c737 100644
--- 
a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
+++ 
b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
@@ -175,10 +175,11 @@ public class EnumerableWindow extends Window implements 
EnumerableRel {
 
     PhysType inputPhysType = result.physType;
 
+    final int w = implementor.windowCount++;
     ParameterExpression prevStart =
-        Expressions.parameter(int.class, builder.newName("prevStart"));
+        Expressions.parameter(int.class, builder.newName("prevStart" + w));
     ParameterExpression prevEnd =
-        Expressions.parameter(int.class, builder.newName("prevEnd"));
+        Expressions.parameter(int.class, builder.newName("prevEnd" + w));
 
     builder.add(Expressions.declare(0, prevStart, null));
     builder.add(Expressions.declare(0, prevEnd, null));

http://git-wip-us.apache.org/repos/asf/calcite/blob/a1fe7691/core/src/test/resources/sql/winagg.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/winagg.iq 
b/core/src/test/resources/sql/winagg.iq
index e755670..809db77 100644
--- a/core/src/test/resources/sql/winagg.iq
+++ b/core/src/test/resources/sql/winagg.iq
@@ -404,4 +404,30 @@ order by gender, r;
 
 !ok
 
+# [CALCITE-2081] Two windows under a JOIN
+select a."deptno", a.r as ar, b.r as br
+from (
+  select "deptno", first_value("empid") over w as r
+  from "hr"."emps"
+  window w as (partition by "deptno" order by "commission")) a
+join (
+  select "deptno", last_value("empid") over w as r
+  from "hr"."emps"
+  window w as (partition by "deptno" order by "commission")) b
+on a."deptno" = b."deptno"
+limit 5;
+
++--------+-----+-----+
+| deptno | AR  | BR  |
++--------+-----+-----+
+|     10 | 110 | 110 |
+|     10 | 110 | 110 |
+|     10 | 110 | 110 |
+|     20 | 200 | 200 |
+|     20 | 200 |     |
++--------+-----+-----+
+(5 rows)
+
+!ok
+
 # End winagg.iq

Reply via email to