Skip to content

fix: inherit field names from left projection in set expressions when missing#20819

Open
gruuya wants to merge 1 commit intoapache:mainfrom
splitgraph:fix-set-expr-double-literal-unaliased
Open

fix: inherit field names from left projection in set expressions when missing#20819
gruuya wants to merge 1 commit intoapache:mainfrom
splitgraph:fix-set-expr-double-literal-unaliased

Conversation

@gruuya
Copy link
Contributor

@gruuya gruuya commented Mar 9, 2026

Which issue does this PR close?

Rationale for this change

DataFusion requires all projected expressions to have unique names during planning, so it doesn't support select 0, 0 for instance.

However this shouldn't be an issue when this is just a sub-SELECT in a larger query which does abide by this rule. For example a set expression (UNION, EXCEPT, INTERSECT) query should only require the first SELECT to provide a unique schema, and that should be sufficient.

Furthermore, this requirement is even more redundant, since all field name/aliases other than those in the first SELECT are discarded anyway.

What changes are included in this PR?

For set expression queries, alias all unnamed right-hand side projection expressions based on the left-hand side column names.

This is only done in the case for literals, other expression types should have default unique names.

Are these changes tested?

Yes, there are SQL->plan tests as well as SLT tests added.

Are there any user-facing changes?

@github-actions github-actions bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Mar 9, 2026
@gruuya gruuya force-pushed the fix-set-expr-double-literal-unaliased branch 5 times, most recently from 15cf2d7 to 66c5fcc Compare March 9, 2026 20:39
… missing

Otherwise they might end up having the same column names, which is prohibited.
This is only the case for literals, other expression types should have default unique names.
@gruuya gruuya force-pushed the fix-set-expr-double-literal-unaliased branch from 66c5fcc to 4aa6a92 Compare March 9, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected set expression query planning error

1 participant