Skip to content

fix: ignore constant aggregate completion boundaries - #25019

Merged
sunchao merged 1 commit into
apache:mainfrom
yashrb24:fix/ignore-constant-group-completion
Sep 16, 2026
Merged

sunchao merged 1 commit into
apache:mainfrom
yashrb24:fix/ignore-constant-group-completion

Conversation

@yashrb24

@yashrb24 yashrb24 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

A grouping column with one fixed value never changes, so it cannot tell aggregation that an earlier group is complete.
Currently the logic uses such columns when choosing how aggregation processes its input. This can select the ordered path even when the remaining grouping columns are not ordered.

What changes are included in this PR?

  • Ignore fixed grouping columns when deciding when groups can be completed.
  • Preserve ordered aggregation when all grouping columns that can change are ordered.
  • Update relevant plans

What is the testing strategy for this PR?

Added tests for a grouping column fixed by a filter. The tests fail without the fix.

Are there any user-facing changes?

No query results or public APIs change. DataFusion now chooses the appropriate aggregation path for fixed grouping columns.

@github-actions github-actions Bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Sep 7, 2026
@yashrb24

yashrb24 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Since #24697 is making the broader fix for this problem, we can possibly have it fixed in that PR instead of here

@yashrb24
yashrb24 marked this pull request as ready for review September 7, 2026 12:08
@codecov-commenter

codecov-commenter commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.92683% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.90%. Comparing base (c2cf289) to head (41eda67).

Files with missing lines Patch % Lines
datafusion/physical-plan/src/aggregates/mod.rs 82.92% 2 Missing and 12 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25019      +/-   ##
==========================================
- Coverage   81.90%   81.90%   -0.01%     
==========================================
  Files        1134     1134              
  Lines      425261   425341      +80     
  Branches   425261   425341      +80     
==========================================
+ Hits       348325   348363      +38     
- Misses      56295    56320      +25     
- Partials    20641    20658      +17     

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

@sunchao sunchao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @yashrb24, LGTM.

Ignoring constant grouping keys for completion detection correctly rejects unbounded plans that cannot finish groups, while preserving incremental output when a varying grouping key is genuinely ordered.

Reviewed commit 037c8cf with five independent passes. Focused base/head validation passed 2,376 SQL cases per revision, eight paired streaming checks, and 40 low-memory cases per revision, including 16 spilling cases each. No actionable regressions found.

Regular and extended CI suites passed. The forced-hash-collision job timed out in unchanged COUNT DISTINCT capacity tests outside the modified aggregation code.

@yashrb24
yashrb24 force-pushed the fix/ignore-constant-group-completion branch from 037c8cf to 41eda67 Compare September 14, 2026 07:37
@sunchao
sunchao added this pull request to the merge queue Sep 16, 2026
Merged via the queue into apache:main with commit 6ff484a Sep 16, 2026
41 checks passed
adriangb pushed a commit to pydantic/datafusion that referenced this pull request Sep 16, 2026
Resolving the rebase conflict in `aggregates/mod.rs` took this branch's
copy of the whole file, which reverted the changes made upstream while the
branch was in flight:

- `constant_grouping_expr_is_not_a_completion_boundary` and the imports it
  needs, added with the constant-boundary fix (apache#25019). That fix's
  non-test half moved into the builder with the rest of the construction
  logic, so only the test was missing.
- the `test_grouped_aggregation_respects_memory_limit` assertion, which
  upstream relaxed to match on `e.find_root()`. Aggregate spilling reports
  a `ResourcesExhausted` wrapped in a `Context`, which the older assertion
  could not see through.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PwTc51ca2XHDCyVB7MbJoz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt) v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A fixed GROUP BY column is incorrectly used to decide when groups are complete

4 participants