Jackie-Jiang commented on code in PR #13573:
URL: https://github.com/apache/pinot/pull/13573#discussion_r1674525731
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotAggregateReduceFunctionsRule.java:
##########
@@ -16,21 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.pinot.calcite.sql.fun;
+package org.apache.pinot.calcite.rel.rules;
-import org.apache.calcite.sql.SqlCall;
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.fun.SqlCoalesceFunction;
-import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.rel.core.AggregateCall;
+import org.apache.calcite.rel.rules.AggregateReduceFunctionsRule;
+import org.apache.calcite.sql.SqlKind;
/**
- * Pinot supports native COALESCE function, thus no need to create CASE WHEN
conversion.
+ * Pinot customized version of {@link AggregateReduceFunctionsRule} which only
reduce on SUM and AVG.
*/
-public class PinotSqlCoalesceFunction extends SqlCoalesceFunction {
+public class PinotAggregateReduceFunctionsRule extends
AggregateReduceFunctionsRule {
+ public static final PinotAggregateReduceFunctionsRule INSTANCE =
+ new PinotAggregateReduceFunctionsRule(Config.DEFAULT);
+
+ private PinotAggregateReduceFunctionsRule(Config config) {
+ super(config);
+ }
@Override
- public SqlNode rewriteCall(SqlValidator validator, SqlCall call) {
- return call;
+ public boolean canReduce(AggregateCall call) {
+ SqlKind kind = call.getAggregation().getKind();
+ return kind == SqlKind.SUM || kind == SqlKind.AVG;
Review Comment:
When this rule is applied, we don't have leaf stage concept yet (leaf stage
is determined with `PinotAggregateExchangeNodeInsertRule`).
We don't really need these rewrite because Pinot can directly handle `SUM`
and `AVG` with proper null handling (the rule is needed for engine without
proper null handling). I didn't directly remove the rule because that is out of
the scope of this PR, and null handling support requires some more tweaks.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]