{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/20345","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/20345/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/20345/comments","events_url":"https://api.github.com/repos/apache/spark/issues/20345/events","html_url":"https://github.com/apache/spark/pull/20345","id":290295789,"node_id":"MDExOlB1bGxSZXF1ZXN0MTY0MTg4ODgz","number":20345,"title":"[SPARK-23172][SQL] Expand the ReorderJoin rule to handle Project nodes","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":74,"created_at":"2018-01-21T18:52:21Z","updated_at":"2018-08-03T11:19:18Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/20345","html_url":"https://github.com/apache/spark/pull/20345","diff_url":"https://github.com/apache/spark/pull/20345.diff","patch_url":"https://github.com/apache/spark/pull/20345.patch"},"body":"## What changes were proposed in this pull request?\r\nThe current `ReorderJoin` optimizer rule cannot flatten a pattern `Join -> Project -> Join` because `ExtractFiltersAndInnerJoins` doesn't handle `Project` nodes. So, the current master cannot reorder joins in a query below;\r\n```\r\nval df1 = spark.range(100).selectExpr(\"id % 10 AS k0\", s\"id % 10 AS k1\", s\"id % 10 AS k2\", \"id AS v1\")\r\nval df2 = spark.range(10).selectExpr(\"id AS k0\", \"id AS v2\")\r\nval df3 = spark.range(10).selectExpr(\"id AS k1\", \"id AS v3\")\r\nval df4 = spark.range(10).selectExpr(\"id AS k2\", \"id AS v4\")\r\ndf1.join(df2, \"k0\").join(df3, \"k1\").join(df4, \"k2\").explain(true)\r\n\r\n== Analyzed Logical Plan ==\r\nk2: bigint, k1: bigint, k0: bigint, v1: bigint, v2: bigint, v3: bigint, v4: bigint\r\nProject [k2#5L, k1#4L, k0#3L, v1#6L, v2#16L, v3#24L, v4#32L]\r\n+- Join Inner, (k2#5L = k2#31L)\r\n   :- Project [k1#4L, k0#3L, k2#5L, v1#6L, v2#16L, v3#24L]\r\n   :  +- Join Inner, (k1#4L = k1#23L)\r\n   :     :- Project [k0#3L, k1#4L, k2#5L, v1#6L, v2#16L]\r\n   :     :  +- Join Inner, (k0#3L = k0#15L)\r\n   :     :     :- Project [(id#0L % cast(10 as bigint)) AS k0#3L, (id#0L % cast(10 as bigint)) AS k1#4L, (id#0L % cast(10 as bigint)) AS k2#5L, id#0\r\nL AS v1#6L]\r\n   :     :     :  +- Range (0, 100, step=1, splits=Some(4))\r\n   :     :     +- Project [id#12L AS k0#15L, id#12L AS v2#16L]\r\n   :     :        +- Range (0, 10, step=1, splits=Some(4))\r\n   :     +- Project [id#20L AS k1#23L, id#20L AS v3#24L]\r\n   :        +- Range (0, 10, step=1, splits=Some(4))\r\n   +- Project [id#28L AS k2#31L, id#28L AS v4#32L]\r\n      +- Range (0, 10, step=1, splits=Some(4))\r\n```\r\nTo reorder the query, this pr added code to handle `Project` in `ExtractFiltersAndInnerJoins`.\r\n\r\nThis pr also fixed an output attribute reorder problem when joins reordered; it checks if a join reordered plan and an original plan have the same output attribute order with each other. If not, `ReorderJoin` adds `Project` in the top of the join reordered plan.\r\n\r\n## How was this patch tested?\r\nThis pr added new tests in `JoinOptimizationSuite` and modified some existing tests in `StarJoinReorderSuite` to check if `ReorderJoin` can handle `Project` nodes correctly. Also, it modified the existing tests in `JoinReorderSuite` for the output attribute reorder issue."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/410223812","html_url":"https://github.com/apache/spark/pull/20345#issuecomment-410223812","issue_url":"https://api.github.com/repos/apache/spark/issues/20345","id":410223812,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDIyMzgxMg==","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-08-03T11:19:18Z","updated_at":"2018-08-03T11:19:18Z","author_association":"NONE","body":"Merged build finished. Test PASSed."}}
{"actor":{"display_login":"AmplabJenkins"}}