-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18597][SQL] Do not push-down join conditions to the right side of a LEFT ANTI join #16026
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7696cf2
Fix 2.10 compilation
hvanhovell d51b635
Merge remote-tracking branch 'apache-github/master'
hvanhovell 7ccb680
Merge remote-tracking branch 'apache-github/master'
hvanhovell e386fed
Merge remote-tracking branch 'apache-github/master'
hvanhovell 4d6b183
Do not change left anti join semantics by pushing down to the right s…
hvanhovell 47bbdff
CR: Modify test name
hvanhovell 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| -- SPARK-18597: Do not push down predicates to left hand side in an anti-join | ||
| CREATE OR REPLACE TEMPORARY VIEW tbl_a AS VALUES (1, 1), (2, 1), (3, 6) AS T(c1, c2); | ||
| CREATE OR REPLACE TEMPORARY VIEW tbl_b AS VALUES 1 AS T(c1); | ||
|
|
||
| SELECT * | ||
| FROM tbl_a | ||
| LEFT ANTI JOIN tbl_b ON ((tbl_a.c1 = tbl_a.c2) IS NULL OR tbl_a.c1 = tbl_a.c2); |
29 changes: 29 additions & 0 deletions
29
sql/core/src/test/resources/sql-tests/results/anti-join.sql.out
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 3 | ||
|
|
||
|
|
||
| -- !query 0 | ||
| CREATE OR REPLACE TEMPORARY VIEW tbl_a AS VALUES (1, 1), (2, 1), (3, 6) AS T(c1, c2) | ||
| -- !query 0 schema | ||
| struct<> | ||
| -- !query 0 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 1 | ||
| CREATE OR REPLACE TEMPORARY VIEW tbl_b AS VALUES 1 AS T(c1) | ||
| -- !query 1 schema | ||
| struct<> | ||
| -- !query 1 output | ||
|
|
||
|
|
||
|
|
||
| -- !query 2 | ||
| SELECT * | ||
| FROM tbl_a | ||
| LEFT ANTI JOIN tbl_b ON ((tbl_a.c1 = tbl_a.c2) IS NULL OR tbl_a.c1 = tbl_a.c2) | ||
| -- !query 2 schema | ||
| struct<c1:int,c2:int> | ||
| -- !query 2 output | ||
| 2 1 | ||
| 3 6 |
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.
The semantics of
ExistenceJoinsays we need to preserve all the rows from the left table through the join operation as if it is a regularLeftOuterjoin. TheExistenceJoinaugments theLeftOuteroperation with a new column called exists, set to true when the join condition in the ON clause is true and false otherwise. The filter of any rows will happen in the Filter operation above theExistenceJoin.Example:
A(c1, c2):
{ (1, 1), (1, 2) }
B(c1):
{ (NULL) }
// can be any value as it is irrelevant in this example
In this example, the correct result is all the rows from A. If the pattern
ExistenceJoinat line 935 inOptimizer.scalaadded by the PR of this JIRA is indeed active, the code will push down the predicateA.c1 = A.c2to be a Filter on relation A, which will filter the row (1,2) from A.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.
@nsyca Have you tried the above example using the latest master?
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 should have included the full comment from the JIRA. The keyword is "this is not currently exposed". Here is the first part of my comment:
"
ExistenceJoinshould be treated the same asLeftOuterandLeftAnti, notInnerLikeandLeftSemi. This is not currently exposed because the rewrite of[NOT] EXISTS OR ...toExistenceJoinhappens in ruleRewritePredicateSubquery, which is in a separate rule set and placed after the rulePushPredicateThroughJoin. During the transformation in the rulePushPredicateThroughJoin, anExistenceJoinnever exists."