Skip to content

[SPARK-53308] [SQL] Don't remove aliases in RemoveRedundantAliases that would cause duplicates #52060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mihailoale-db
Copy link
Contributor

What changes were proposed in this pull request?

In case a Project, Aggregate or Window is a child of Union, we don't remove an Alias in case it is on top of an Attribute which exists in the output set of the operator. This is needed because otherwise, we end up having an operator with duplicates in its output. When that happens, Union is not resolved and we fail (but we shouldn't).
Consider this example:

SELECT col1 FROM values(1) WHERE 100 IN (SELECT col1 UNION SELECT col1);

In this PR I propose that we fix above query (it should pass, now it fails) by not removing Aliases under Union that would cause duplicates.

Why are the changes needed?

To fix a query pattern.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Added test.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Aug 18, 2025
@mihailoale-db mihailoale-db changed the title initial commit [SPARK-53308] [SQL] Don't remove aliases in RemoveRedundantAliases that would cause duplicates Aug 18, 2025
@mihailoale-db mihailoale-db force-pushed the unionduplicates branch 9 times, most recently from f4d84dc to 4b170e8 Compare August 19, 2025 12:59
@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 967f2b6 Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants