hsyuan commented on a change in pull request #1078: [CALCITE-896] Remove
Aggregate if grouping columns are unique and all functions are splittable
URL: https://github.com/apache/calcite/pull/1078#discussion_r261502471
##########
File path:
core/src/main/java/org/apache/calcite/rel/rules/AggregateRemoveRule.java
##########
@@ -51,41 +62,64 @@ public AggregateRemoveRule(Class<? extends Aggregate>
aggregateClass) {
*/
public AggregateRemoveRule(Class<? extends Aggregate> aggregateClass,
RelBuilderFactory relBuilderFactory) {
- // REVIEW jvs 14-Mar-2006: We have to explicitly mention the child here
- // to make sure the rule re-fires after the child changes (e.g. via
- // ProjectRemoveRule), since that may change our information
- // about whether the child is distinct. If we clean up the inference of
- // distinct to make it correct up-front, we can get rid of the reference
- // to the child here.
super(
- operand(aggregateClass,
- operand(RelNode.class, any())),
- relBuilderFactory, null);
+ operandJ(aggregateClass, null, agg -> isAggregateSupported(agg),
+ any()), relBuilderFactory, null);
+ }
+
+ private static boolean isAggregateSupported(Aggregate aggregate) {
+ if (aggregate.indicator
+ || aggregate.getGroupType() != Aggregate.Group.SIMPLE
+ || aggregate.getGroupCount() == 0) {
+ return false;
+ }
+ // If any aggregate functions do not support splitting, bail out.
+ // Also bail out for SUM0 because it may be generated by SUM
+ // when reducing aggregate functions to avoid potential infinite
+ // rule matching.
+ for (AggregateCall aggregateCall : aggregate.getAggCallList()) {
+ if (aggregateCall.filterArg >= 0
+ || aggregateCall.getAggregation().getKind() == SqlKind.SUM0
Review comment:
Bail out for SUM0 temporarily, otherwise there will be infinite rule
matching for `JdbcTest.testHavingNo` and `JdbcTest.testHavingNot2`. Will log
another issue.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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