-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-26352][SQL] join reorder should not change the order of output attributes #23303
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
5715fe3
a23b191
917300d
5e52fab
713e01d
43e9ac4
9451b68
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 |
|---|---|---|
|
|
@@ -895,4 +895,18 @@ class JoinSuite extends QueryTest with SharedSQLContext { | |
| checkAnswer(res, Row(0, 0, 0)) | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-26352: join reordering should not change the order of columns") { | ||
| withTable("tab1", "tab2", "tab3") { | ||
|
||
| spark.sql("select 1 as x, 100 as y").write.saveAsTable("tab1") | ||
| spark.sql("select 42 as i, 200 as j").write.saveAsTable("tab2") | ||
| spark.sql("select 1 as a, 42 as b").write.saveAsTable("tab3") | ||
|
|
||
| val df = spark.sql(""" | ||
| with tmp as (select * from tab1 cross join tab2) | ||
| select * from tmp join tab3 on a = x and b = i | ||
| """) | ||
| checkAnswer(df, Row(1, 100, 42, 200, 1, 42)) | ||
|
||
| } | ||
| } | ||
| } | ||
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.
just for curiosity, we only need this for top-level join? I feel it's ok to change the columnar order for intermedia joins.
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.
That's right, only the top-level really needs to maintain the appearance. But this is the easiest to implement (the change is local to the rule where order could have changed, so this projection is easier to understand than adding it elsewhere), and it doesn't affect the final result because other optimizer rules are actually going to get rid of the extra intermediate projections.
e.g. if on top of the
df, we do an extra operation:you're going to see that the extra
Projectgets optimized away in:(a few other rules may also remove the extra
Project)