rednaxelafx commented on a change in pull request #23303: [SPARK-26352][SQL]
ReorderJoin should not change the order of columns
URL: https://github.com/apache/spark/pull/23303#discussion_r241251128
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/JoinSuite.scala
##########
@@ -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))
Review comment:
Yeah, before sending this PR I've actually explicitly run both test cases
that I added with and without the fix, and verified that without the fix it'd
fail the test.
The reason why you "think" it works in your environment is because you used
`show`, which after @maropu 's earlier PR will introduce a `Project` at the
top, which happens to cure the issue.
If you just do a `collect` you'll see the problem still exists:
```
scala> df.show
+---+---+---+---+---+---+
| x| y| i| j| a| b|
+---+---+---+---+---+---+
| 1|100| 42|200| 1| 42|
+---+---+---+---+---+---+
scala> df.collect
res5: Array[org.apache.spark.sql.Row] = Array([1,100,1,42,42,200])
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]