Repository navigation
fix(expr): preserve unique right-branch aliases in set operations - #27936
Open
warrenzhu25 wants to merge 1 commit into
Open
warrenzhu25 wants to merge 1 commit into
warrenzhu25 wants to merge 1 commit into
Conversation
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?
Rationale for this change
#27473 updated
project_with_validationto unconditionally rename everyExpr::Aliasin the right branch of a set operation to the corresponding field name from the left branch's schema. Becauseselect_to_planrunsself.project(...)before resolvingGROUP BY,HAVING,QUALIFY, andDISTINCT ON, renaming unique user aliases caused those clauses to either fail withNo field named ...or silently resolve to the wrong expression when alias names were swapped between branches.What changes are included in this PR?
project_with_validation(datafusion/expr/src/logical_plan/builder.rs), count output names before renaming and preserve uniqueExpr::Aliasnames so downstream clauses in the right branch can still resolve them.1 AS x, 2 AS xorcount(*), count(*)) and non-Column/non-Alias expressions, tracking reserved names so renaming never introduces a secondary collision with a preserved user alias or column.datafusion/sqllogictest/test_files/union.sltcoveringUNION ALL/UNION/INTERSECT/EXCEPTwithGROUP BY, swapped-aliasHAVING,QUALIFY,DISTINCT ON, and collision edge cases.Are these changes tested?
cargo test --test sqllogictests -- unioncargo test -p datafusion-sql --test sql_integration union(10/10 passed, existing snapshots unchanged)cargo test -p datafusion-expr --lib logical_plan::builder(30/30 passed)cargo fmt --allandcargo clippy -p datafusion-expr -p datafusion-sql --all-targets -- -D warningsAre there any user-facing changes?
Fixes a regression on
main(unreleased) so right branches of set operations can again reference their ownSELECTaliases inGROUP BY,HAVING,QUALIFY, andDISTINCT ON. No public API changes.Note: Developed with AI assistance; all changes and tests were reviewed and verified by me.