fix: [branch-54] keep GROUP BY-less aggregates when propagating empty stages (backport of #2194) - #2235
Merged
andygrove merged 1 commit intoAug 6, 2026
Conversation
…stages (apache#2194) (cherry picked from commit 7eeff3b)
andygrove
marked this pull request as ready for review
August 6, 2026 12:47
phillipleblanc
approved these changes
Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Backport of #2194 to
branch-54. The issue it fixes is #2185.Rationale for this change
With the adaptive planner, a query stage that completes with zero rows makes
ExchangeExec::partition_statisticsreportPrecision::Exact(0), andPropagateEmptyExecRulethen collapses the plan above it on the next replan.That rule replaced any
AggregateExecwhose input had become empty with anEmptyExec. This is only valid when the aggregate has aGROUP BY. An aggregate with no grouping expressions emits exactly one row even over zero input rows (sumreturns NULL,countreturns 0), so collapsing it silently drops that row. DataFusion's logicalPropagateEmptyRelationrule carries the same guard (!agg.group_expr.is_empty()); the physical port here was missing it.TPC-DS q61 hits this at SF1 because no store has
s_gmt_offset = -7, so thestorestage legitimately returns zero rows. The correct answer is a single all-NULL row, which single-process DataFusion and the static planner both produce, but the adaptive planner returned no rows at all.This is a silent wrong answer rather than a failure, which is why it is worth carrying onto the release branch.
What changes are included in this PR?
A clean cherry-pick of 7eeff3b, unmodified.
Guards the
AggregateExecarm ofPropagateEmptyExecRuleon!aggregation.group_expr().is_empty(), so a grouping-less aggregate is left in place over an empty input.Adds three unit tests covering the aggregate arm: the grouped case still collapses, and the
SingleandPartialgrouping-less cases are preserved. Both new grouping-less tests fail before the change.Are there any user-facing changes?
No API changes. Queries run under
ballista.planner.adaptive.enabled=truethat contain a grouping-less aggregate over an input that turns out to be empty now return the correct single row instead of no rows. The static planner is unaffected.Verified locally on the
branch-54base:cargo fmt --all -- --checkis clean, andcargo check --workspace --all-targets --lockedcompletes with no warnings on a combined stack of the six backports being proposed together. Test execution is left to CI.