[SPARK-41912][SQL] Subquery should not validate CTE #39414
Closed
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?
The commit #38029 actually intended to do the right thing: it checks CTE more aggressively even if a CTE is not used, which is ok. However, it triggers an existing issue where a subquery checks itself but in the CTE case if the subquery contains a CTE which is defined outside of the subquery, the check will fail as CTE not found (e.g. key not found).
So it is:
the commit checks more thus in the repro examples, every CTE is checked now (in the past only used CTE is checked).
One of the CTE that is checked after the commit in the example contains subquery.
The subquery contains another CTE which is defined outside of the subquery.
The subquery checks itself thus fail due to CTE not found.
This PR fixes the issue by removing the subquery self-validation on CTE case.
Why are the changes needed?
This fixed a regression that
cannot pass analyzer anymore.
Does this PR introduce any user-facing change?
No
How was this patch tested?
UT