{"action":"closed","number":15600,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/15600","id":90494445,"html_url":"https://github.com/apache/spark/pull/15600","diff_url":"https://github.com/apache/spark/pull/15600.diff","patch_url":"https://github.com/apache/spark/pull/15600.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/15600","number":15600,"state":"closed","locked":false,"title":"[SPARK-17698] [SQL] Join predicates should not contain filter clauses","user":{"login":"tejasapatil","id":3230057,"avatar_url":"https://avatars.githubusercontent.com/u/3230057?v=3","gravatar_id":"","url":"https://api.github.com/users/tejasapatil","html_url":"https://github.com/tejasapatil","followers_url":"https://api.github.com/users/tejasapatil/followers","following_url":"https://api.github.com/users/tejasapatil/following{/other_user}","gists_url":"https://api.github.com/users/tejasapatil/gists{/gist_id}","starred_url":"https://api.github.com/users/tejasapatil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejasapatil/subscriptions","organizations_url":"https://api.github.com/users/tejasapatil/orgs","repos_url":"https://api.github.com/users/tejasapatil/repos","events_url":"https://api.github.com/users/tejasapatil/events{/privacy}","received_events_url":"https://api.github.com/users/tejasapatil/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nThis is a backport of https://github.com/apache/spark/pull/15272 to 2.0 branch.\r\n\r\nJira : https://issues.apache.org/jira/browse/SPARK-17698\r\n\r\n`ExtractEquiJoinKeys` is incorrectly using filter predicates as the join condition for joins. `canEvaluate` [0] tries to see if the an `Expression` can be evaluated using output of a given `Plan`. In case of filter predicates (eg. `a.id='1'`), the `Expression` passed for the right hand side (ie. '1' ) is a `Literal` which does not have any attribute references. Thus `expr.references` is an empty set which theoretically is a subset of any set. This leads to `canEvaluate` returning `true` and `a.id='1'` is treated as a join predicate. While this does not lead to incorrect results but in case of bucketed + sorted tables, we might miss out on avoiding un-necessary shuffle + sort. See example below:\r\n\r\n[0] : https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala#L91\r\n\r\neg.\r\n\r\n```\r\nval df = (1 until 10).toDF(\"id\").coalesce(1)\r\nhc.sql(\"DROP TABLE IF EXISTS table1\").collect\r\ndf.write.bucketBy(8, \"id\").sortBy(\"id\").saveAsTable(\"table1\")\r\nhc.sql(\"DROP TABLE IF EXISTS table2\").collect\r\ndf.write.bucketBy(8, \"id\").sortBy(\"id\").saveAsTable(\"table2\")\r\n\r\nsqlContext.sql(\"\"\"\r\n  SELECT a.id, b.id\r\n  FROM table1 a\r\n  FULL OUTER JOIN table2 b\r\n  ON a.id = b.id AND a.id='1' AND b.id='1'\r\n\"\"\").explain(true)\r\n```\r\n\r\nBEFORE: This is doing shuffle + sort over table scan outputs which is not needed as both tables are bucketed and sorted on the same columns and have same number of buckets. This should be a single stage job.\r\n\r\n```\r\nSortMergeJoin [id#38, cast(id#38 as double), 1.0], [id#39, 1.0, cast(id#39 as double)], FullOuter\r\n:- *Sort [id#38 ASC NULLS FIRST, cast(id#38 as double) ASC NULLS FIRST, 1.0 ASC NULLS FIRST], false, 0\r\n:  +- Exchange hashpartitioning(id#38, cast(id#38 as double), 1.0, 200)\r\n:     +- *FileScan parquet default.table1[id#38] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table1, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>\r\n+- *Sort [id#39 ASC NULLS FIRST, 1.0 ASC NULLS FIRST, cast(id#39 as double) ASC NULLS FIRST], false, 0\r\n   +- Exchange hashpartitioning(id#39, 1.0, cast(id#39 as double), 200)\r\n      +- *FileScan parquet default.table2[id#39] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table2, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>\r\n```\r\n\r\nAFTER :\r\n\r\n```\r\nSortMergeJoin [id#32], [id#33], FullOuter, ((cast(id#32 as double) = 1.0) && (cast(id#33 as double) = 1.0))\r\n:- *FileScan parquet default.table1[id#32] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table1, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>\r\n+- *FileScan parquet default.table2[id#33] Batched: true, Format: ParquetFormat, InputPaths: file:spark-warehouse/table2, PartitionFilters: [], PushedFilters: [], ReadSchema: struct<id:int>\r\n```\r\n\r\n## How was this patch tested?\r\n\r\n- Added a new test case for this scenario : `SPARK-17698 Join predicates should not contain filter clauses`\r\n- Ran all the tests in `BucketedReadSuite`","created_at":"2016-10-22T20:29:20Z","updated_at":"2016-10-22T23:44:41Z","closed_at":"2016-10-22T23:44:41Z","merged_at":null,"merge_commit_sha":"96abfc77f4363c9c9b118b9f9c8b19de2aef81e8","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/15600/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/15600/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/15600/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/df5083894198e1a85fb17544fc596a3869a9e1b6","head":{"label":"tejasapatil:SPARK-17698_2.0_backport","ref":"SPARK-17698_2.0_backport","sha":"df5083894198e1a85fb17544fc596a3869a9e1b6","user":{"login":"tejasapatil","id":3230057,"avatar_url":"https://avatars.githubusercontent.com/u/3230057?v=3","gravatar_id":"","url":"https://api.github.com/users/tejasapatil","html_url":"https://github.com/tejasapatil","followers_url":"https://api.github.com/users/tejasapatil/followers","following_url":"https://api.github.com/users/tejasapatil/following{/other_user}","gists_url":"https://api.github.com/users/tejasapatil/gists{/gist_id}","starred_url":"https://api.github.com/users/tejasapatil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejasapatil/subscriptions","organizations_url":"https://api.github.com/users/tejasapatil/orgs","repos_url":"https://api.github.com/users/tejasapatil/repos","events_url":"https://api.github.com/users/tejasapatil/events{/privacy}","received_events_url":"https://api.github.com/users/tejasapatil/received_events","type":"User","site_admin":false},"repo":{"id":50031489,"name":"spark","full_name":"tejasapatil/spark","owner":{"login":"tejasapatil","id":3230057,"avatar_url":"https://avatars.githubusercontent.com/u/3230057?v=3","gravatar_id":"","url":"https://api.github.com/users/tejasapatil","html_url":"https://github.com/tejasapatil","followers_url":"https://api.github.com/users/tejasapatil/followers","following_url":"https://api.github.com/users/tejasapatil/following{/other_user}","gists_url":"https://api.github.com/users/tejasapatil/gists{/gist_id}","starred_url":"https://api.github.com/users/tejasapatil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tejasapatil/subscriptions","organizations_url":"https://api.github.com/users/tejasapatil/orgs","repos_url":"https://api.github.com/users/tejasapatil/repos","events_url":"https://api.github.com/users/tejasapatil/events{/privacy}","received_events_url":"https://api.github.com/users/tejasapatil/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tejasapatil/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/tejasapatil/spark","forks_url":"https://api.github.com/repos/tejasapatil/spark/forks","keys_url":"https://api.github.com/repos/tejasapatil/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tejasapatil/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tejasapatil/spark/teams","hooks_url":"https://api.github.com/repos/tejasapatil/spark/hooks","issue_events_url":"https://api.github.com/repos/tejasapatil/spark/issues/events{/number}","events_url":"https://api.github.com/repos/tejasapatil/spark/events","assignees_url":"https://api.github.com/repos/tejasapatil/spark/assignees{/user}","branches_url":"https://api.github.com/repos/tejasapatil/spark/branches{/branch}","tags_url":"https://api.github.com/repos/tejasapatil/spark/tags","blobs_url":"https://api.github.com/repos/tejasapatil/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tejasapatil/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tejasapatil/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/tejasapatil/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tejasapatil/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/tejasapatil/spark/languages","stargazers_url":"https://api.github.com/repos/tejasapatil/spark/stargazers","contributors_url":"https://api.github.com/repos/tejasapatil/spark/contributors","subscribers_url":"https://api.github.com/repos/tejasapatil/spark/subscribers","subscription_url":"https://api.github.com/repos/tejasapatil/spark/subscription","commits_url":"https://api.github.com/repos/tejasapatil/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/tejasapatil/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/tejasapatil/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/tejasapatil/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/tejasapatil/spark/contents/{+path}","compare_url":"https://api.github.com/repos/tejasapatil/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tejasapatil/spark/merges","archive_url":"https://api.github.com/repos/tejasapatil/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tejasapatil/spark/downloads","issues_url":"https://api.github.com/repos/tejasapatil/spark/issues{/number}","pulls_url":"https://api.github.com/repos/tejasapatil/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/tejasapatil/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/tejasapatil/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tejasapatil/spark/labels{/name}","releases_url":"https://api.github.com/repos/tejasapatil/spark/releases{/id}","deployments_url":"https://api.github.com/repos/tejasapatil/spark/deployments","created_at":"2016-01-20T13:22:03Z","updated_at":"2016-01-20T13:22:28Z","pushed_at":"2016-10-22T20:18:37Z","git_url":"git://github.com/tejasapatil/spark.git","ssh_url":"git@github.com:tejasapatil/spark.git","clone_url":"https://github.com/tejasapatil/spark.git","svn_url":"https://github.com/tejasapatil/spark","homepage":null,"size":245729,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:branch-2.0","ref":"branch-2.0","sha":"b959dab32a455e0f9a9ea0fd2111e28a5faf796c","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-10-22T22:04:25Z","pushed_at":"2016-10-22T23:33:09Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":601805,"stargazers_count":10458,"watchers_count":10458,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9739,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":483,"forks":9739,"open_issues":483,"watchers":10458,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/15600"},"html":{"href":"https://github.com/apache/spark/pull/15600"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/15600"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/15600/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/15600/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/15600/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/df5083894198e1a85fb17544fc596a3869a9e1b6"}},"merged":false,"mergeable":true,"mergeable_state":"clean","merged_by":null,"comments":2,"review_comments":0,"commits":1,"additions":79,"deletions":14,"changed_files":4}}
{"actor":{"display_login":"tejasapatil"}}