-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-23564][SQL] Add isNotNull check for left anti and outer joins #20717
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,4 +204,40 @@ class InferFiltersFromConstraintsSuite extends PlanTest { | |
val optimized = Optimize.execute(originalQuery) | ||
comparePlans(optimized, correctAnswer) | ||
} | ||
|
||
test("SPARK-23564: left anti join should filter out null join keys on right side") { | ||
val x = testRelation.subquery('x) | ||
val y = testRelation.subquery('y) | ||
val condition = Some("x.a".attr === "y.a".attr) | ||
val originalQuery = x.join(y, LeftAnti, condition).analyze | ||
val left = x | ||
val right = y.where(IsNotNull('a)) | ||
val correctAnswer = left.join(right, LeftAnti, condition).analyze | ||
val optimized = Optimize.execute(originalQuery) | ||
comparePlans(optimized, correctAnswer) | ||
} | ||
|
||
test("SPARK-23564: left outer join should filter out null join keys on right side") { | ||
val x = testRelation.subquery('x) | ||
val y = testRelation.subquery('y) | ||
val condition = Some("x.a".attr === "y.a".attr) | ||
val originalQuery = x.join(y, LeftOuter, condition).analyze | ||
val left = x | ||
val right = y.where(IsNotNull('a)) | ||
val correctAnswer = left.join(right, LeftOuter, condition).analyze | ||
val optimized = Optimize.execute(originalQuery) | ||
comparePlans(optimized, correctAnswer) | ||
} | ||
|
||
test("SPARK-23564: right outer join should filter out null join keys on left side") { | ||
val x = testRelation.subquery('x) | ||
val y = testRelation.subquery('y) | ||
val condition = Some("x.a".attr === "y.a".attr) | ||
val originalQuery = x.join(y, RightOuter, condition).analyze | ||
val left = x.where(IsNotNull('a)) | ||
val right = y | ||
val correctAnswer = left.join(right, RightOuter, condition).analyze | ||
val optimized = Optimize.execute(originalQuery) | ||
comparePlans(optimized, correctAnswer) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a simple repetition of the previous private def testConstraints(
x: LogicalPlan, y: LogicalPlan, left: LogicalPlan, right: LogicalPlan, joinType: JoinType) = {
val condition = Some("x.a".attr === "y.a".attr)
val originalQuery = x.join(y, joinType, condition).analyze
val correctAnswer = left.join(right, joinType, condition).analyze
val optimized = Optimize.execute(originalQuery)
comparePlans(optimized, correctAnswer)
}
test("SPARK-23405: left-semi equal-join should filter out null join keys on both sides") {
val x = testRelation.subquery('x)
val y = testRelation.subquery('y)
testConstraints(x, y, x.where(IsNotNull('a)), y.where(IsNotNull('a)), LeftSemi)
}
test("SPARK-23564: left anti join should filter out null join keys on right side") {
val x = testRelation.subquery('x)
val y = testRelation.subquery('y)
testConstraints(x, y, x, y.where(IsNotNull('a)), LeftAnti)
}
test("SPARK-23564: left outer join should filter out null join keys on right side") {
val x = testRelation.subquery('x)
val y = testRelation.subquery('y)
testConstraints(x, y, x, y.where(IsNotNull('a)), LeftOuter)
}
test("SPARK-23564: right outer join should filter out null join keys on left side") {
val x = testRelation.subquery('x)
val y = testRelation.subquery('y)
testConstraints(x, y, x.where(IsNotNull('a)), y, RightOuter)
} |
||
} |
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.
why not put this in
Join.validConstraints
?LogicalPlan.constraints
should only contain constraints for the plab output, butLogicalPlan.allConstraints
can contain more.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 haven't put it there, because
constraints
is created fromallConstraints
, so adding them tovalidConstraints
could have caused them to be part ofconstraints
too.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.
ah i see the problem. For left-anti join, although
Join.output
reuse the attributes from left child output, they are actually different attributes, e.g. Join may output null values, so we can't generate these constraints inJoin.validConstraints
.I think we can override both
allConstraints
andconstraints
, to make sure these extra constraints appear inallConstraints
, but notconstraints
.