{"action":"closed","number":10169,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/10169","id":52803637,"html_url":"https://github.com/apache/spark/pull/10169","diff_url":"https://github.com/apache/spark/pull/10169.diff","patch_url":"https://github.com/apache/spark/pull/10169.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/10169","number":10169,"state":"closed","locked":false,"title":"[SPARK-12167][SQL] Invoke the right sameResult function when plan is warpped with SubQueries","user":{"login":"watermen","id":1400819,"avatar_url":"https://avatars.githubusercontent.com/u/1400819?v=3","gravatar_id":"","url":"https://api.github.com/users/watermen","html_url":"https://github.com/watermen","followers_url":"https://api.github.com/users/watermen/followers","following_url":"https://api.github.com/users/watermen/following{/other_user}","gists_url":"https://api.github.com/users/watermen/gists{/gist_id}","starred_url":"https://api.github.com/users/watermen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watermen/subscriptions","organizations_url":"https://api.github.com/users/watermen/orgs","repos_url":"https://api.github.com/users/watermen/repos","events_url":"https://api.github.com/users/watermen/events{/privacy}","received_events_url":"https://api.github.com/users/watermen/received_events","type":"User","site_admin":false},"body":"### Bug\r\nI find this bug when I use cache table,\r\n```\r\nspark-sql> create table src_p(key int, value int) stored as parquet;\r\nOK\r\nTime taken: 3.144 seconds\r\nspark-sql> cache table src_p;\r\nTime taken: 1.452 seconds\r\nspark-sql> explain extended select count(*) from src_p;\r\n```\r\nI got the wrong physical plan\r\n```\r\n== Physical Plan ==\r\nTungstenAggregate(key=[], functions=[(count(1),mode=Final,isDistinct=false)], output=[_c0#28L])\r\n TungstenExchange SinglePartition\r\n  TungstenAggregate(key=[], functions=[(count(1),mode=Partial,isDistinct=false)], output=[currentCount#33L])\r\n   Scan ParquetRelation[hdfs://9.91.8.131:9000/user/hive/warehouse/src_p][]\r\n```\r\nand the right physical plan is\r\n```\r\n== Physical Plan ==\r\nTungstenAggregate(key=[], functions=[(count(1),mode=Final,isDistinct=false)], output=[_c0#47L])\r\n TungstenExchange SinglePartition\r\n  TungstenAggregate(key=[], functions=[(count(1),mode=Partial,isDistinct=false)], output=[currentCount#62L])\r\n   InMemoryColumnarTableScan (InMemoryRelation [key#45,value#46], true, 10000, StorageLevel(true, true, false, true, 1), (Scan ParquetRelation[hdfs://9.91.8.131:9000/user/hive/warehouse/src_p][key#9,value#10]), Some(src_p))\r\n```\r\n### Reason\r\nWhen the implementation classes of `MultiInstanceRelation`(eg. `LogicalRelation`, `LocalRelation`) are warpped with SubQueries, they can't invoke the right `sameResult` function in their own implementation. So we need to eliminate SubQueries first and then try to invoke `sameResult` function in their own implementation.\r\nLike:\r\nWhen plan is `Subquery(LogicalRelation(relation:ParquetRelation[hdfs://9.91.8.131:9000/user/hive/warehouse/src_p], expectedOutputAttributes:Some(ArrayBuffer(key#0, value#1))))`, first eliminate SubQueries, and then will invoke the `sameResult` function in `LogicalRelation` instead of `LogicalPlan`.","created_at":"2015-12-07T04:00:39Z","updated_at":"2015-12-07T07:16:23Z","closed_at":"2015-12-07T07:16:23Z","merged_at":null,"merge_commit_sha":"494000ca6f4e6c33549519aba851399ea7f36b53","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/10169/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/10169/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/10169/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/f1ef856ee4fa45bcd2143bf164dab61f6f17ce63","head":{"label":"watermen:patch-2","ref":"patch-2","sha":"f1ef856ee4fa45bcd2143bf164dab61f6f17ce63","user":{"login":"watermen","id":1400819,"avatar_url":"https://avatars.githubusercontent.com/u/1400819?v=3","gravatar_id":"","url":"https://api.github.com/users/watermen","html_url":"https://github.com/watermen","followers_url":"https://api.github.com/users/watermen/followers","following_url":"https://api.github.com/users/watermen/following{/other_user}","gists_url":"https://api.github.com/users/watermen/gists{/gist_id}","starred_url":"https://api.github.com/users/watermen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watermen/subscriptions","organizations_url":"https://api.github.com/users/watermen/orgs","repos_url":"https://api.github.com/users/watermen/repos","events_url":"https://api.github.com/users/watermen/events{/privacy}","received_events_url":"https://api.github.com/users/watermen/received_events","type":"User","site_admin":false},"repo":{"id":26309097,"name":"spark","full_name":"watermen/spark","owner":{"login":"watermen","id":1400819,"avatar_url":"https://avatars.githubusercontent.com/u/1400819?v=3","gravatar_id":"","url":"https://api.github.com/users/watermen","html_url":"https://github.com/watermen","followers_url":"https://api.github.com/users/watermen/followers","following_url":"https://api.github.com/users/watermen/following{/other_user}","gists_url":"https://api.github.com/users/watermen/gists{/gist_id}","starred_url":"https://api.github.com/users/watermen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watermen/subscriptions","organizations_url":"https://api.github.com/users/watermen/orgs","repos_url":"https://api.github.com/users/watermen/repos","events_url":"https://api.github.com/users/watermen/events{/privacy}","received_events_url":"https://api.github.com/users/watermen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/watermen/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/watermen/spark","forks_url":"https://api.github.com/repos/watermen/spark/forks","keys_url":"https://api.github.com/repos/watermen/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/watermen/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/watermen/spark/teams","hooks_url":"https://api.github.com/repos/watermen/spark/hooks","issue_events_url":"https://api.github.com/repos/watermen/spark/issues/events{/number}","events_url":"https://api.github.com/repos/watermen/spark/events","assignees_url":"https://api.github.com/repos/watermen/spark/assignees{/user}","branches_url":"https://api.github.com/repos/watermen/spark/branches{/branch}","tags_url":"https://api.github.com/repos/watermen/spark/tags","blobs_url":"https://api.github.com/repos/watermen/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/watermen/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/watermen/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/watermen/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/watermen/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/watermen/spark/languages","stargazers_url":"https://api.github.com/repos/watermen/spark/stargazers","contributors_url":"https://api.github.com/repos/watermen/spark/contributors","subscribers_url":"https://api.github.com/repos/watermen/spark/subscribers","subscription_url":"https://api.github.com/repos/watermen/spark/subscription","commits_url":"https://api.github.com/repos/watermen/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/watermen/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/watermen/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/watermen/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/watermen/spark/contents/{+path}","compare_url":"https://api.github.com/repos/watermen/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/watermen/spark/merges","archive_url":"https://api.github.com/repos/watermen/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/watermen/spark/downloads","issues_url":"https://api.github.com/repos/watermen/spark/issues{/number}","pulls_url":"https://api.github.com/repos/watermen/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/watermen/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/watermen/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/watermen/spark/labels{/name}","releases_url":"https://api.github.com/repos/watermen/spark/releases{/id}","created_at":"2014-11-07T07:37:56Z","updated_at":"2015-02-04T02:18:35Z","pushed_at":"2015-12-07T03:47:05Z","git_url":"git://github.com/watermen/spark.git","ssh_url":"git@github.com:watermen/spark.git","clone_url":"https://github.com/watermen/spark.git","svn_url":"https://github.com/watermen/spark","homepage":null,"size":130418,"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:master","ref":"master","sha":"80a824d36eec9d9a9f092ee1741453851218ec73","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}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-12-07T07:13:49Z","pushed_at":"2015-12-07T07:14:36Z","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":389692,"stargazers_count":6479,"watchers_count":6479,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5997,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":404,"forks":5997,"open_issues":404,"watchers":6479,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/10169"},"html":{"href":"https://github.com/apache/spark/pull/10169"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/10169"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/10169/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/10169/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/10169/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/f1ef856ee4fa45bcd2143bf164dab61f6f17ce63"}},"merged":false,"mergeable":true,"mergeable_state":"clean","merged_by":null,"comments":3,"review_comments":0,"commits":1,"additions":19,"deletions":10,"changed_files":1}}