Skip to content

refactor(hash-aggr): route grouping sets to the migrated hash streams - #24870

Open
2010YOUY01 wants to merge 1 commit into
apache:mainfrom
2010YOUY01:split-aggr-grouping-sets
Open

refactor(hash-aggr): route grouping sets to the migrated hash streams#24870
2010YOUY01 wants to merge 1 commit into
apache:mainfrom
2010YOUY01:split-aggr-grouping-sets

Conversation

@2010YOUY01

@2010YOUY01 2010YOUY01 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of #22710

Rationale for this change

Let aggregate with grouping sets get route into the newly refactored aggregation (see above EPIC for backgrounds)

What changes are included in this PR?

The key change is at datafusion/physical-plan/src/aggregates/mod.rs, it changes the planning decision as described above

What is the testing strategy for this PR?

Existing tests.

  • TODO for myself: check codecov to ensure good test coverage

Are there any user-facing changes?

No

`GROUPING SETS` / `CUBE` / `ROLLUP` still fell back to the legacy
`GroupedHashAggregateStream`, because the migrated partial and single
stream predicates required a plain `GROUP BY`. Grouping sets are always
planned with `InputOrderMode::Linear` since apache#24422, and the shared
`AggregateHashTable` already expands every grouping set of an input
batch, so they can run on `PartialHashAggregateStream` and
`SingleHashAggregateStream`.

- Move `init_empty_grouping_sets` from the partial table into the shared
  table, so single aggregation also emits the grand-total group on empty
  input.
- Drop the `is_single()` condition from the partial and single stream
  predicates. The final and partial-reduce predicates keep it, because
  state-input stages must receive the expanded keys as a plain group by.
- The spill-mode `check_grouping_sets` snapshot changes because the
  migrated partial stream flushes after every batch under memory
  pressure; the final results are unchanged.

Part of apache#22710

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Sep 2, 2026
| 3 | | 1 | 1 |
| 3 | | 1 | 2 |
| 3 | 2.0 | 0 | 2 |
| 3 | 2.0 | 0 | 1 |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are valid outputs for partial aggregation with early emit; the difference is because execution is not 100% the same between the legacy and refactored implementations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering in case of distinct and regular aggregation, usually dedup should be on the partial stage?

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.23404% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.61%. Comparing base (1608ee7) to head (be7c63a).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...plan/src/aggregates/aggregate_hash_table/common.rs 89.13% 0 Missing and 5 partials ⚠️
...rc/aggregates/aggregate_hash_table/single_table.rs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24870      +/-   ##
==========================================
- Coverage   81.61%   81.61%   -0.01%     
==========================================
  Files        1123     1123              
  Lines      409562   409634      +72     
  Branches   409562   409634      +72     
==========================================
+ Hits       334284   334341      +57     
- Misses      55647    55655       +8     
- Partials    19631    19638       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jayzhan211 jayzhan211 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants