{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/17400","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/17400/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/17400/comments","events_url":"https://api.github.com/repos/apache/spark/issues/17400/events","html_url":"https://github.com/apache/spark/pull/17400","id":216492470,"node_id":"MDExOlB1bGxSZXF1ZXN0MTEyMjgyMjAy","number":17400,"title":"[SPARK-19981][SQL] Respect aliases in output partitioning of projects and aggregates","user":{"login":"maropu","id":692303,"node_id":"MDQ6VXNlcjY5MjMwMw==","avatar_url":"https://avatars3.githubusercontent.com/u/692303?v=4","gravatar_id":"","url":"https://api.github.com/users/maropu","html_url":"https://github.com/maropu","followers_url":"https://api.github.com/users/maropu/followers","following_url":"https://api.github.com/users/maropu/following{/other_user}","gists_url":"https://api.github.com/users/maropu/gists{/gist_id}","starred_url":"https://api.github.com/users/maropu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maropu/subscriptions","organizations_url":"https://api.github.com/users/maropu/orgs","repos_url":"https://api.github.com/users/maropu/repos","events_url":"https://api.github.com/users/maropu/events{/privacy}","received_events_url":"https://api.github.com/users/maropu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":37,"created_at":"2017-03-23T16:34:03Z","updated_at":"2018-09-18T02:09:30Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/17400","html_url":"https://github.com/apache/spark/pull/17400","diff_url":"https://github.com/apache/spark/pull/17400.diff","patch_url":"https://github.com/apache/spark/pull/17400.patch"},"body":"## What changes were proposed in this pull request?\r\nThe current master might wrongly add shuffle operations when projects and aggregates in physical plans have  aliases in output expressions. A concrete example is as follows;\r\n```\r\nscala> :paste\r\nsql(\"SET spark.sql.autoBroadcastJoinThreshold=-1\")\r\nspark.range(10).selectExpr(\"id AS key\", \"0\").repartition($\"key\").createOrReplaceTempView(\"df1\")\r\nspark.range(10).selectExpr(\"id AS key\", \"0\").repartition($\"key\").createOrReplaceTempView(\"df2\")\r\nsql(\"\"\"\r\n  SELECT * FROM\r\n    (SELECT key AS k from df1) t1\r\n  INNER JOIN\r\n    (SELECT key AS k from df2) t2\r\n  ON t1.k = t2.k\r\n\"\"\").explain\r\n\r\n== Physical Plan ==\r\n*SortMergeJoin [k#56L], [k#57L], Inner\r\n:- *Sort [k#56L ASC NULLS FIRST], false, 0\r\n:  +- Exchange hashpartitioning(k#56L, 200)     // <--- Unnecessary ShuffleExchange\r\n:     +- *Project [key#39L AS k#56L]\r\n:        +- Exchange hashpartitioning(key#39L, 200)\r\n:           +- *Project [id#36L AS key#39L]\r\n:              +- *Range (0, 10, step=1, splits=Some(4))\r\n+- *Sort [k#57L ASC NULLS FIRST], false, 0\r\n   +- ReusedExchange [k#57L], Exchange hashpartitioning(k#56L, 200)\r\n```\r\n\r\nIn 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 requirement checks in `EnsureRequirements`. This pr proposes to handle these aliases in `EnsureRequirements` so as to check if the operators satisfy their output distribution requirements.\r\n\r\n## How was this patch tested?\r\nAdded tests in `SQLQueryTestSuite`."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/422229675","html_url":"https://github.com/apache/spark/pull/17400#issuecomment-422229675","issue_url":"https://api.github.com/repos/apache/spark/issues/17400","id":422229675,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMjIyOTY3NQ==","user":{"login":"AmplabJenkins","id":4031291,"node_id":"MDQ6VXNlcjQwMzEyOTE=","avatar_url":"https://avatars3.githubusercontent.com/u/4031291?v=4","gravatar_id":"","url":"https://api.github.com/users/AmplabJenkins","html_url":"https://github.com/AmplabJenkins","followers_url":"https://api.github.com/users/AmplabJenkins/followers","following_url":"https://api.github.com/users/AmplabJenkins/following{/other_user}","gists_url":"https://api.github.com/users/AmplabJenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/AmplabJenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AmplabJenkins/subscriptions","organizations_url":"https://api.github.com/users/AmplabJenkins/orgs","repos_url":"https://api.github.com/users/AmplabJenkins/repos","events_url":"https://api.github.com/users/AmplabJenkins/events{/privacy}","received_events_url":"https://api.github.com/users/AmplabJenkins/received_events","type":"User","site_admin":false},"created_at":"2018-09-18T02:09:29Z","updated_at":"2018-09-18T02:09:29Z","author_association":"NONE","body":"Test FAILed.\nRefer to this link for build results (access rights to CI server needed): \nhttps://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/96161/\nTest FAILed."}}
{"actor":{"display_login":"AmplabJenkins"}}