Repository navigation
Conversation
adriangb
added a commit
to pydantic/datafusion
that referenced
this pull request
Oct 15, 2026
Carried from apache#26356 (open).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26356 +/- ##
==========================================
+ Coverage 82.83% 82.89% +0.05%
==========================================
Files 1151 1153 +2
Lines 455332 457542 +2210
Branches 455332 457542 +2210
==========================================
+ Hits 377165 379257 +2092
- Misses 55262 55272 +10
- Partials 22905 23013 +108 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Removing aliases from redundant group keys discards their output field metadata.
1 open finding
What changed in this PR
Fixes EliminateGroupByConstant incorrectly requalifying group expressions when rebuilding an aggregate’s output projection.
Changes:
- Builds the projection directly from aggregate output columns.
- Leaves grouping-set aggregates unchanged.
- Adds a regression test for unqualified references to qualified inputs.
| File | Description |
|---|---|
| datafusion/optimizer/src/eliminate_group_by_constant.rs | Updates projection construction, guards grouping sets, and adds regression coverage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
adriangb
added a commit
to pydantic/datafusion
that referenced
this pull request
Oct 16, 2026
Carried from apache#26356 (open).
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?
No issue filed. The reproduction is below.
Rationale for this change
EliminateGroupByConstantre-plans the original group expressions over the newAggregatewithLogicalPlanBuilder::project. Column normalization falls back to the input schema of the aggregate. Thus an unqualified group expression, such as an extracted leaf__datafusion_extracted_1, becomesm.__datafusion_extracted_1when the input is aSubqueryAlias: m. The new aggregate does not output that name, and the rule fails:The input plan is valid, and the rule turns it into an invalid one. We reach it when we optimize a plan, bind its parameters with
replace_params_with_values, and optimize again. The bound value makes a group key redundant only afterExtractLeafExpressionshas rewritten the plan. In a singleoptimizecall,EliminateGroupByConstantruns beforeExtractLeafExpressionsin each pass, so I could not reproduce it there. Since #26184, the arguments of filtered aggregates no longer go into a common-expression projection between the aggregate and the alias, so the aggregate can sit directly on the alias and the problem shows.What changes are included in this PR?
Projection::try_newand does not re-plan the group expressions. A kept key or an aggregate becomes a column of the schema of the new aggregate. A redundant key keeps its expression, which reads only bare GROUP BY columns that the new aggregate outputs unchanged. An item gets an alias only when its name differs from the original output field, so existing plans do not change.GroupingSetunchanged, because its output fields do not map one to one togroup_expr.What is the testing strategy for this PR?
test_eliminate_with_unqualified_reference_to_qualified_input. It fails without the change, with the same schema error.cargo test -p datafusion-optimizerandcargo test -p datafusion-sqllogictest --test sqllogictestspass. No existing plan changes.Are there any user-facing changes?
No API changes. A plan that failed in this rule now optimizes.