ulysses-you opened a new pull request, #58106: URL: https://github.com/apache/spark/pull/58106
### What changes were proposed in this pull request? Extend runtime adaptive partial aggregation (`spark.sql.execution.aggregate.adaptivePartialAggregation.enabled`) to support the DISTINCT intermediate phase, whose aggregate modes are `PartialMerge ++ Partial` (non-distinct aggregates in `PartialMerge`, distinct aggregates in `Partial`). Previously the feature only bypassed partial aggregates whose functions were all in `Partial` mode, so this phase was excluded. ### Why are the changes needed? Bypassing a `PartialMerge` member is safe because the pass-through merges the incoming buffer into an empty buffer, which leaves it unchanged (the existing first-insertion of a key already relies on `merge(initial, x) == x`), and the downstream `Final` re-merges it. This lets high-cardinality DISTINCT queries benefit from the bypass. A pure `PartialMerge` de-duplication phase must still not bypass (it would over-count DISTINCT); it is kept out by its required distribution plus a defensive `exists(_.mode == Partial)` guard. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Added tests to `AdaptivePartialAggregationSuite` covering DISTINCT with plain and filtered non-distinct aggregates, and an imperative aggregate in the DISTINCT intermediate phase. ### Was this patch authored or co-authored using generative AI tooling? Yes. Generated-by: Claude Code (Anthropic). -- 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]
