vineetgarg02 commented on a change in pull request #1087: [CALCITE-1172] Add 
rule to flatten two Aggregate operators into one
URL: https://github.com/apache/calcite/pull/1087#discussion_r264482287
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/sql/SqlSplittableAggFunction.java
 ##########
 @@ -268,6 +303,19 @@ public AggregateCall topSplit(RexBuilder rexBuilder,
           aggregateCall.type, aggregateCall.name);
     }
 
+    public AggregateCall merge(AggregateCall top, AggregateCall bottom) {
+      SqlKind topKind = top.getAggregation().getKind();
+      if (topKind == bottom.getAggregation().getKind()
+          && (topKind == SqlKind.SUM
+              || topKind == SqlKind.SUM0)) {
+        return AggregateCall.create(bottom.getAggregation(), 
bottom.isDistinct(),
+            bottom.isApproximate(), bottom.getArgList(), bottom.filterArg,
+            bottom.getCollation(), bottom.getType(), top.getName());
+      } else {
+        return null;
+      }
+    }
+
 
 Review comment:
   Another test case where both top and bottom aggregate has empty group by and 
are mergeable (e.g. SUM of SUM) would be nice.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to