You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[SPARK-53308][SQL] Don't remove aliases in RemoveRedundantAliases that would cause duplicates
### 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 `Alias`es 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.
Closes#52060 from mihailoale-db/unionduplicates.
Authored-by: mihailoale-db <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
Copy file name to clipboardExpand all lines: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RemoveRedundantAliasAndProjectSuite.scala
0 commit comments