-
Notifications
You must be signed in to change notification settings - Fork 29.2k
[SPARK-52498][SQL] Fix false ambiguous self-join error with foldable condition #56056
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
shrirangmhalgi
wants to merge
1
commit into
apache:master
from
shrirangmhalgi:SPARK-52498-self-join-ambiguity
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the premise of this exemption needs reconsidering — the case it allows is genuinely ambiguous.
The justification in the comment is inaccurate. "The foldable condition means it doesn't matter which side the column comes from" is not true. The condition
df("col") === 0resolves to one side only (LEFT, sincedf("col")carries LEFT's exprId afterResolveDeduplicateRelations). The join is effectively:That filters
L.col = 0but leavesR.colunconstrained. Fordf = [0, 1, 2]:select df("col"))→ LEFT.col →[0, 0, 0]. Selecting the right side (hypothetically) would give[0, 1, 2]. The two sides do not agree. (NoteJoinWith.resolveSelfJoinConditiononly rewrites trivially-trueEqualTo(a, b) if a.sameRef(b)—df("col") === 0is not rewritten.)So the column reference is ambiguous in exactly the way this rule exists to flag: the user wrote
df("col")and got LEFT, but a reasonable reader ofdf.join(df, df("col") === 0).select(df("col"))might expect the result to be "col from the join result" — which isn't a single well-defined thing.Internal consistency with the existing tests.
SPARK-28344: fail ambiguous self join - column ref in ProjectinDataFrameSelfJoinSuite(line 148) already establishes thatself_join.select(df("col"))is ambiguous and must throw. The PR carves out an exemption when the join condition happens to contain a foldable equality — but the foldable equality does no semantic work here (it doesn't make L.col == R.col, doesn't makedf("col")resolve any differently). It's just the discriminator that separates the new test case from the four existing tests that broke with the broader fix mentioned in the PR description. Without a principled reason, this looks like reverse-engineering the rule to fit one test.Implication for the motivation. The PR description says the single-pass resolver handles this "correctly." If we agree the case is ambiguous, then single-pass is the one with the bug — the right direction is to align single-pass with
DetectAmbiguousSelfJoin(preserve the error), not to weakenDetectAmbiguousSelfJoin.Would you mind reconsidering the direction? Happy to discuss if there's a use case I'm missing — but as-is I don't think we should land this exemption.