siddharthteotia commented on a change in pull request #1033: [CALCITE-2820] Add
a version of AggregateReduceFunctionsRule that does not reduce SUM to SUM0
URL: https://github.com/apache/calcite/pull/1033#discussion_r263123392
##########
File path:
core/src/main/java/org/apache/calcite/rel/rules/AggregateReduceFunctionsRule.java
##########
@@ -97,12 +98,96 @@
new AggregateReduceFunctionsRule(operand(LogicalAggregate.class, any()),
RelFactories.LOGICAL_BUILDER);
+ private final AggregateFunctionsToReduce functionsToReduce;
+
+ /**
+ * Used to create a non-default version of this rule
+ * where we can be specific about which functions
+ * should be reduced by the rule
+ */
+ public static class AggregateFunctionsToReduce {
+ private final boolean reduceAvg;
+ private final boolean reduceSum;
+ private final boolean reduceStddevPop;
+ private final boolean reduceStddevSamp;
+ private final boolean reduceVarPop;
+ private final boolean reduceVarSamp;
+ private final boolean reduceCovarPop;
+ private final boolean reduceCovarSamp;
+ private final boolean reduceRegrSxx;
+ private final boolean reduceRegrSyy;
+
+ private AggregateFunctionsToReduce() {
+ this.reduceAvg = true;
+ this.reduceSum = true;
+ this.reduceStddevPop = true;
+ this.reduceStddevSamp = true;
+ this.reduceVarPop = true;
+ this.reduceVarSamp = true;
+ this.reduceCovarPop = true;
+ this.reduceCovarSamp = true;
+ this.reduceRegrSxx = true;
+ this.reduceRegrSyy = true;
+ }
+
+ public AggregateFunctionsToReduce(final boolean reduceAvg, final boolean
reduceSum,
+ final boolean reduceStddevPop, final boolean reduceStddevSamp,
+ final boolean reduceVarPop, final boolean reduceVarSamp,
+ final boolean reduceCovarPop, final boolean reduceCovarSamp,
+ final boolean reduceRegrSxx, final boolean reduceRegrSyy) {
+ this.reduceAvg = reduceAvg;
+ this.reduceSum = reduceSum;
+ this.reduceStddevPop = reduceStddevPop;
+ this.reduceStddevSamp = reduceStddevSamp;
+ this.reduceVarPop = reduceVarPop;
+ this.reduceVarSamp = reduceVarSamp;
+ this.reduceCovarPop = reduceCovarPop;
+ this.reduceCovarSamp = reduceCovarSamp;
+ this.reduceRegrSxx = reduceRegrSxx;
+ this.reduceRegrSyy = reduceRegrSyy;
+ }
+ }
+
+ /**
+ * Gets an instance of AggregateReduceFunctionsRule
+ * with client provided specific functions to reduce
+ * @param functionsToReduce client provided information
+ * on which specific functions will be
+ * reduced by this rule
+ * @return an instance of AggregateReduceFunctionsRule
+ */
+ public static AggregateReduceFunctionsRule
+ getInstanceWithSpecificFunctionsToReduce(final
AggregateFunctionsToReduce functionsToReduce) {
+ Preconditions.checkArgument(functionsToReduce != null,
+ "Error: expecting a valid handle for AggregateFunctionsToReduce");
+ return new AggregateReduceFunctionsRule(operand(LogicalAggregate.class,
any()),
+ RelFactories.LOGICAL_BUILDER, functionsToReduce);
+ }
+
//~ Constructors -----------------------------------------------------------
/** Creates an AggregateReduceFunctionsRule. */
public AggregateReduceFunctionsRule(RelOptRuleOperand operand,
RelBuilderFactory relBuilderFactory) {
super(operand, relBuilderFactory, null);
+ // by default, this rule will reduce all functions it handles
+ this.functionsToReduce = new AggregateFunctionsToReduce();
+ }
+
+ /**
+ * Creates an AggregateReduceFunctionsRule with client
+ * provided information on which specific functions will
+ * be reduced by this rule
+ * @param operand root operand
+ * @param relBuilderFactory builder for relational expressions
+ * @param functionsToReduce client provided information
+ * on which specific functions
+ * will be reduced by this rule
+ */
+ public AggregateReduceFunctionsRule(RelOptRuleOperand operand,
+ RelBuilderFactory relBuilderFactory, final AggregateFunctionsToReduce
functionsToReduce) {
Review comment:
Thanks. I am using a Set<SqlKind> now.
----------------------------------------------------------------
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