GitHub user maropu opened a pull request:
https://github.com/apache/spark/pull/17400
[SPARK-19981][SQL] Update output partitioning info. in ProjectExec when
having aliases
## What changes were proposed in this pull request?
The current master wrongly adds `ShuffleExchange` when operator's
`requiredChildDistribution` refers to aliases. A concrete example is as follows;
```
scala> :paste
sql("SET spark.sql.autoBroadcastJoinThreshold=-1")
spark.range(10).selectExpr("id AS key",
"0").repartition($"key").createOrReplaceTempView("df1")
spark.range(10).selectExpr("id AS key",
"0").repartition($"key").createOrReplaceTempView("df2")
sql("""
SELECT * FROM
(SELECT key AS k from df1) t1
INNER JOIN
(SELECT key AS k from df2) t2
ON t1.k = t2.k
""").explain
== Physical Plan ==
*SortMergeJoin [k#56L], [k#57L], Inner
:- *Sort [k#56L ASC NULLS FIRST], false, 0
: +- Exchange hashpartitioning(k#56L, 200) // <--- Unnecessary
ShuffleExchange
: +- *Project [key#39L AS k#56L]
: +- Exchange hashpartitioning(key#39L, 200)
: +- *Project [id#36L AS key#39L]
: +- *Range (0, 10, step=1, splits=Some(4))
+- *Sort [k#57L ASC NULLS FIRST], false, 0
+- ReusedExchange [k#57L], Exchange hashpartitioning(k#56L, 200)
```
In the query, the second `Exchange` is not necessary. The root cause is
that the planner wrongly regards `key` and `k` as different attributes because
they have different `exprId`. Then, it fails distribution checks in
`EnsureRequirements`. This pr is to update output partitioning info. in
`ProjectExec` when projection lists having aliases.
## How was this patch tested?
Added tests in `SQLQueryTestSuite`.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/maropu/spark SPARK-19981
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/17400.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #17400
----
commit b5d1038edffff5d65a6ddec20ea6eef186d25fc3
Author: Takeshi Yamamuro <[email protected]>
Date: 2017-03-23T16:12:28Z
Update partitioning info. in ProjectExec when having aliases
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]