Skip to content

refactor(hash-aggr): migrate ordered single aggregation - #24259

Merged
2010YOUY01 merged 2 commits into
apache:mainfrom
2010YOUY01:split-aggr-01-ordered-single
Aug 13, 2026
Merged

refactor(hash-aggr): migrate ordered single aggregation#24259
2010YOUY01 merged 2 commits into
apache:mainfrom
2010YOUY01:split-aggr-01-ordered-single

Conversation

@2010YOUY01

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

part of #22710

Rationale for this change

Migrate ordered single aggregation path.

For the background of the refactor, see EPIC issue for details

For the overview of the refactored path, see comments at the top of datafusion/physical-plan/src/aggregates/ordered_single_stream.rs

What changes are included in this PR?

  • datafusion/physical-plan/src/aggregates/mod.rs: physical planning changes that route the applicable execution to the 'ordered-single-aggregate` path
  • datafusion/physical-plan/src/aggregates/ordered_single_stream.rs: main implementation. Overview is at the comments for OrderedSingleAggregateStream, and the entry point for execution state machine is at poll_next()

Are these changes tested?

Existing tests. I have verified the test line coverage from llvm-cov

Are there any user-facing changes?

No

@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Aug 11, 2026
@2010YOUY01 2010YOUY01 changed the title refactor: migrate ordered single aggregation refactor(hash-aggr): migrate ordered single aggregation Aug 11, 2026
}

/// Merges every sorted run and finalizes it through the fully ordered path.
fn into_replay_stream(

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.

This step is mostly similar to the spilling paths of other aggregation modes. We should extract the common logic later.

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.

maybe worth a ticket to track

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.

&mut self,
evaluated_batch: &EvaluatedAggregateBatch,
is_final: bool,
aggregate_fn: AggregateBatchFn,

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.

here is the key change for this file, just a clean-up to make it easier to be reused by different aggregation modes.

@codecov-commenter

codecov-commenter commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.23776% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.13%. Comparing base (634f0b3) to head (af72b61).
⚠️ Report is 76 commits behind head on main.

Files with missing lines Patch % Lines
...sical-plan/src/aggregates/ordered_single_stream.rs 86.74% 49 Missing and 10 partials ⚠️
datafusion/physical-plan/src/aggregates/mod.rs 87.17% 5 Missing and 5 partials ⚠️
.../aggregates/aggregate_hash_table/common_ordered.rs 60.00% 0 Missing and 2 partials ⚠️
...gates/aggregate_hash_table/ordered_single_table.rs 94.44% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24259      +/-   ##
==========================================
+ Coverage   81.06%   81.13%   +0.07%     
==========================================
  Files        1107     1112       +5     
  Lines      382191   386685    +4494     
  Branches   382191   386685    +4494     
==========================================
+ Hits       309805   313741    +3936     
- Misses      54083    54464     +381     
- Partials    18303    18480     +177     

☔ 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.

@alamb alamb 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.

looks great to me -- thank you @2010YOUY01

)?));
}

if self.should_use_ordered_single_aggregate_stream(context) {

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.

FWIW while I like the explicit name of these methods I do wonder if the difference between them might be clearer if there was one giant match statement (rather than a bunch of if ... chains)

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.

For example the only difference between should_use_single_hash_stream and should_use_ordered_single_aggregate_stream seems to be the condition

            && self.input_order_mode != InputOrderMode::Linear

🤔

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.

This is a good point, I've noticed it also. This entire code block can likely be simplified somehow to be more understandable.

I've opened a issue #24318, and I'll try to do it after the refactor is done.

Comment thread datafusion/physical-plan/src/aggregates/mod.rs Outdated
}

/// Merges every sorted run and finalizes it through the fully ordered path.
fn into_replay_stream(

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.

maybe worth a ticket to track

@2010YOUY01

Copy link
Copy Markdown
Contributor Author

Thanks for the review @alamb

@2010YOUY01
2010YOUY01 added this pull request to the merge queue Aug 13, 2026
Merged via the queue into apache:main with commit 186f96f Aug 13, 2026
40 checks passed
@2010YOUY01
2010YOUY01 deleted the split-aggr-01-ordered-single branch August 13, 2026 03:59
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.

3 participants