You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/07/02 02:26:05 UTC
[GitHub] [calcite] liyafan82 commented on a change in pull request #2447: [CALCITE-4661]Add MODE aggregate function(NobiGo)
liyafan82 commented on a change in pull request #2447:
URL: https://github.com/apache/calcite/pull/2447#discussion_r662694899
##########
File path: core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
##########
@@ -1241,6 +1243,81 @@ public static Expression multiplyDivide(Expression e, BigDecimal multiplier,
}
}
+ /** Implementor for the {@code MODE} aggregate function. */
+ static class ModeImplementor extends StrictAggImplementor {
+ @Override protected void implementNotNullReset(AggContext info,
+ AggResetContext reset) {
+
+ reset.currentBlock().add(
+ Expressions.statement(
+ Expressions.assign(reset.accumulator().get(0),
+ Expressions.constant(null))));
+
+ reset.currentBlock().add(
+ Expressions.statement(
+ Expressions.assign(reset.accumulator().get(1),
+ Expressions.new_(HashMap.class))));
+
+ reset.currentBlock().add(
+ Expressions.statement(
+ Expressions.assign(reset.accumulator().get(2),
+ Expressions.constant(0, Long.class))));
+ }
+
+ @Override protected void implementNotNullAdd(AggContext info,
+ AggAddContext add) {
+ Expression args = add.arguments().get(0);
+
+ Expression accResult = add.accumulator().get(0);
+ Expression accMap = add.accumulator().get(1);
+ Expression accLong = add.accumulator().get(2);
Review comment:
Maybe better variable names could be used here, and some comments could be added to improve readability.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org