[ https://issues.apache.org/jira/browse/IGNITE-20009?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Maksim Zhuravkov updated IGNITE-20009: -------------------------------------- Description: Map/reduce implementation of some aggregates requires replacing an aggregate with a combination of aggregates. For example AVG(col) should be implemented as MAP: SUM(col) sum_col, COUNT (col) as count_col REDUCE: SUM(sum_col)/SUM(COUNT(count_col)) To implement AVG for two phase aggregation we need the following changes: - Replace AVG on MAP phase with SUM and COUNT. - Change rowType produced by MAP phase/accepted by REDUCE phase. - Add a projection after a reduce aggregate that includes division and produces final result (it obviously should include other results of other aggregates in the correct order). Divisor should be checked for 0 in order not to trigger division by zero error. Calcite has `AggregateReduceFunctionsRule` that rewrites AVG aggregate (see reduceAvg method) that code can be used a reference. was: Map/reduce implementation of some aggregates requires replacing an aggregate with a combination of aggregates. For example AVG(col) should be implemented as MAP: SUM(col) sum_col, COUNT (col) as count_col REDUCE: SUM(sum_col)/SUM(COUNT(count_col)) To implement AVG for two phase aggregation we need the following changes: - Replace AVG on MAP phase with SUM and COUNT. - Change rowType produced by MAP phase/accepted by REDUCE phase. - Add a projection after a reduce aggregate that includes division and produces final result (it obviously should include other results of other aggregates in the correct order). Divisor should be checked for 0 in order not to trigger division by zero error. Calcite has `AggregateReduceFunctionsRule` that rewrite AVG aggregate (see reduceAvg method) that code can be used a reference. > Sql. Rework 2-phase aggregates part 2. AVG as SUM / COUNT. > ---------------------------------------------------------- > > Key: IGNITE-20009 > URL: https://issues.apache.org/jira/browse/IGNITE-20009 > Project: Ignite > Issue Type: Improvement > Components: sql > Affects Versions: 3.0.0-beta1 > Reporter: Maksim Zhuravkov > Priority: Minor > Labels: ignite-3 > > Map/reduce implementation of some aggregates requires replacing an aggregate > with a combination of aggregates. For example AVG(col) should be implemented > as > MAP: SUM(col) sum_col, COUNT (col) as count_col > REDUCE: SUM(sum_col)/SUM(COUNT(count_col)) > To implement AVG for two phase aggregation we need the following changes: > - Replace AVG on MAP phase with SUM and COUNT. > - Change rowType produced by MAP phase/accepted by REDUCE phase. > - Add a projection after a reduce aggregate that includes division and > produces final result (it obviously should include other results of other > aggregates in the correct order). Divisor should be checked for 0 in order > not to trigger division by zero error. > Calcite has `AggregateReduceFunctionsRule` that rewrites AVG aggregate (see > reduceAvg method) that code can be used a reference. -- This message was sent by Atlassian Jira (v8.20.10#820010)