Skip to content

refactor(hash-aggr): Let partial-reduce mode aggregation error under memory limit - #24262

Draft
2010YOUY01 wants to merge 4 commits into
apache:mainfrom
2010YOUY01:split-aggr-04-partial-reduce-oom
Draft

refactor(hash-aggr): Let partial-reduce mode aggregation error under memory limit#24262
2010YOUY01 wants to merge 4 commits into
apache:mainfrom
2010YOUY01:split-aggr-04-partial-reduce-oom

Conversation

@2010YOUY01

@2010YOUY01 2010YOUY01 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Part of #22710
Depends on #24261

Only the last commit belongs to this PR. I’ll rebase onto main after the dependent PR is merged.

Rationale for this change

For PartialReduce aggregation, this PR handles the memory limit by returning an error immediately.

Note that the existing behavior when PartialReduce runs out of memory is to spill and then perform final streaming aggregation. This behavior is implemented in the legacy code:
#20019

However, the original PR does not discuss the intended OOM behavior, and there are no tests specifically covering it.

For the major use case of PartialReduce aggregation—reducing data locally before shuffle (datafusion-contrib/datafusion-distributed#360) think early emission may actually be the intended behavior.

I tend to believe the existing behavior was an auto-completion from AI, instead of an intentional design decision. Therefore, this PR takes the more conservative approach of returning an error on OOM. We can revisit and improve this behavior in follow-up PRs.

What changes are included in this PR?

  • partial_reduce_stream.rs: key changes, let aggregation update memory usage during execution, and return error when OOM

Are these changes tested?

UTs

Are there any user-facing changes?

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.46433% with 108 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.00%. Comparing base (634f0b3) to head (74e5613).
⚠️ Report is 42 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 86.39% 8 Missing and 15 partials ⚠️
...sical-plan/src/aggregates/partial_reduce_stream.rs 57.14% 13 Missing and 2 partials ⚠️
...plan/src/aggregates/aggregate_hash_table/common.rs 88.37% 0 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 ⚠️
...c/aggregates/aggregate_hash_table/partial_table.rs 0.00% 0 Missing and 1 partial ⚠️
...rc/aggregates/aggregate_hash_table/single_table.rs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24262      +/-   ##
==========================================
- Coverage   81.06%   81.00%   -0.07%     
==========================================
  Files        1107     1108       +1     
  Lines      382191   384706    +2515     
  Branches   382191   384706    +2515     
==========================================
+ Hits       309805   311612    +1807     
- Misses      54083    54722     +639     
- Partials    18303    18372      +69     

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants