backendArchitect commented on issue #7791: URL: https://github.com/apache/datafusion-comet/issues/7791#issuecomment-7334986311
I tried item 3 in #7795 (closed). Recording why it can't be done: Skipping makes the final aggregate add each skipped row as its own `(value, 1)` state, so the order of additions differs from grouped aggregation. A decimal sum that leaves its precision stays NULL (`or raises in ANSI mode`), as Spark's does, so a different order can overflow where grouped aggregation would have cancelled first. With a `DECIMAL(38, _)` sum, a group of four rows is enough: `[M, 1 - M]` in each of two tasks gives 0.5 when aggregated and NULL when skipped. Limiting the sum precision to below 38 (input precision 12 to 27) gives the sum 10 digits of headroom, but a group of more than `10^10` values still can overflow. @sunchao showed a seeded reducer state (`10^10 * M, 10^10`) followed by [`M, -M`], and nothing bounds the group size. An overflow-safe merge would fix the skipped case but return sums where Spark returns NULL without skipping. So decimal AVG can't be admitted to skipPartial with the same answers as aggregation for every input. The `AvgDecimal::convert_to_state` from #7795 (one-row states that match state()) can be reused if a bounded case ever comes up. Items 1 and 2 (Spark measurements and the default) apply to the Float64 AVG in #7543. -- 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]
