-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-17296][SQL] Simplify parser join processing. #14867
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
Changes from all commits
b25e2db
f9cb0d2
91eafcc
ad1e56b
e20afbd
b09d506
3b13cd7
8edb1e4
fca4489
c30e665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -360,10 +360,54 @@ class PlanParserSuite extends PlanTest { | |
| test("left anti join", LeftAnti, testExistence) | ||
| test("anti join", LeftAnti, testExistence) | ||
|
|
||
| // Test natural cross join | ||
| intercept("select * from a natural cross join b") | ||
|
|
||
| // Test natural join with a condition | ||
| intercept("select * from a natural join b on a.id = b.id") | ||
|
|
||
| // Test multiple consecutive joins | ||
| assertEqual( | ||
| "select * from a join b join c right join d", | ||
| table("a").join(table("b")).join(table("c")).join(table("d"), RightOuter).select(star())) | ||
|
|
||
| // SPARK-17296 | ||
| assertEqual( | ||
| "select * from t1 cross join t2 join t3 on t3.id = t1.id join t4 on t4.id = t1.id", | ||
|
Contributor
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. How is something like
Contributor
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. To clarify, it looks like your patch will disallow both queries at the parser level. Could you add a test that enforces this ?
Contributor
Author
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. Good catch. I have added a test. |
||
| table("t1") | ||
| .join(table("t2"), Cross) | ||
| .join(table("t3"), Inner, Option(Symbol("t3.id") === Symbol("t1.id"))) | ||
| .join(table("t4"), Inner, Option(Symbol("t4.id") === Symbol("t1.id"))) | ||
| .select(star())) | ||
|
|
||
| // Test multiple on clauses. | ||
| intercept("select * from t1 inner join t2 inner join t3 on col3 = col2 on col3 = col1") | ||
|
Contributor
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. As discussed, let's also add a test somewhere for This looks good to me. |
||
|
|
||
| // Parenthesis | ||
| assertEqual( | ||
| "select * from t1 inner join (t2 inner join t3 on col3 = col2) on col3 = col1", | ||
| table("t1") | ||
| .join(table("t2") | ||
| .join(table("t3"), Inner, Option('col3 === 'col2)), Inner, Option('col3 === 'col1)) | ||
| .select(star())) | ||
| assertEqual( | ||
| "select * from t1 inner join (t2 inner join t3) on col3 = col2", | ||
| table("t1") | ||
| .join(table("t2").join(table("t3"), Inner, None), Inner, Option('col3 === 'col2)) | ||
| .select(star())) | ||
| assertEqual( | ||
| "select * from t1 inner join (t2 inner join t3 on col3 = col2)", | ||
| table("t1") | ||
| .join(table("t2").join(table("t3"), Inner, Option('col3 === 'col2)), Inner, None) | ||
| .select(star())) | ||
|
|
||
| // Implicit joins. | ||
| assertEqual( | ||
|
Contributor
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. Great, LGTM |
||
| "select * from t1, t3 join t2 on t1.col1 = t2.col2", | ||
| table("t1") | ||
| .join(table("t3")) | ||
| .join(table("t2"), Inner, Option(Symbol("t1.col1") === Symbol("t2.col2"))) | ||
| .select(star())) | ||
| } | ||
|
|
||
| test("sampled relations") { | ||
|
|
||
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
NATURAL CROSS JOINis invalid, so perhaps we should not includeCROSSinjoinType?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.
You have a point there. Let me update that.
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 had to move the code around. I have added a check in the AstBuilder (spark side of the parser) to catch this.