[SPARK-45580][SQL][3.3] Handle case where a nested subquery becomes an existence join #44223
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.
What changes were proposed in this pull request?
This is a back-port of #44193.
In
RewritePredicateSubquery, prune existence flags from the final join whenrewriteExistentialExprreturns an existence join. This change prunes the flags (attributes with the name "exists") by adding aProjectnode.For example:
becomes
This change always adds the
Projectnode, whetherrewriteExistentialExprreturns an existence join or not. In the case whenrewriteExistentialExprdoes not return an existence join,RemoveNoopOperatorswill remove the unneededProjectnode.Why are the changes needed?
This query returns an extraneous boolean column when run in spark-sql:
(Note: the above query will not have the extraneous boolean column when run from the Dataset API. That is because the Dataset API truncates the rows based on the schema of the analyzed plan. The bug occurs during optimization).
This query fails when run in either spark-sql or using the Dataset API:
Does this PR introduce any user-facing change?
No, except for the removal of the extraneous boolean flag and the fix to the error condition.
How was this patch tested?
New unit test.
Was this patch authored or co-authored using generative AI tooling?
No.