{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/75603771","id":75603771,"diff_hunk":"@@ -151,18 +152,39 @@ case class EnsureRequirements(conf: SQLConf) extends Rule[SparkPlan] {\n   private def ensureDistributionAndOrdering(operator: SparkPlan): SparkPlan = {\n     val requiredChildDistributions: Seq[Distribution] = operator.requiredChildDistribution\n     val requiredChildOrderings: Seq[Seq[SortOrder]] = operator.requiredChildOrdering\n-    var children: Seq[SparkPlan] = operator.children\n-    assert(requiredChildDistributions.length == children.length)\n-    assert(requiredChildOrderings.length == children.length)\n+    assert(requiredChildDistributions.length == operator.children.length)\n+    assert(requiredChildOrderings.length == operator.children.length)\n \n     // Ensure that the operator's children satisfy their output distribution requirements:\n-    children = children.zip(requiredChildDistributions).map {\n-      case (child, distribution) if child.outputPartitioning.satisfies(distribution) =>\n-        child\n-      case (child, BroadcastDistribution(mode)) =>\n-        BroadcastExchangeExec(mode, child)\n-      case (child, distribution) =>\n-        ShuffleExchange(createPartitioning(distribution, defaultNumPreShufflePartitions), child)\n+    val childrenWithDist = operator.children.zip(requiredChildDistributions)\n+\n+    def createShuffleExchange(dist: Distribution, child: SparkPlan) =\n+      ShuffleExchange(createPartitioning(dist, defaultNumPreShufflePartitions), child)\n+\n+    var (parent, children) = if (!AggUtils.isAggregate(operator)) {","path":"sql/core/src/main/scala/org/apache/spark/sql/execution/exchange/EnsureRequirements.scala","position":31,"original_position":31,"commit_id":"91701eb5171555ce73ba6b190b41cc17f05eee8c","original_commit_id":"91701eb5171555ce73ba6b190b41cc17f05eee8c","user":{"login":"hvanhovell","id":9616802,"avatar_url":"https://avatars.githubusercontent.com/u/9616802?v=3","gravatar_id":"","url":"https://api.github.com/users/hvanhovell","html_url":"https://github.com/hvanhovell","followers_url":"https://api.github.com/users/hvanhovell/followers","following_url":"https://api.github.com/users/hvanhovell/following{/other_user}","gists_url":"https://api.github.com/users/hvanhovell/gists{/gist_id}","starred_url":"https://api.github.com/users/hvanhovell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hvanhovell/subscriptions","organizations_url":"https://api.github.com/users/hvanhovell/orgs","repos_url":"https://api.github.com/users/hvanhovell/repos","events_url":"https://api.github.com/users/hvanhovell/events{/privacy}","received_events_url":"https://api.github.com/users/hvanhovell/received_events","type":"User","site_admin":false},"body":"Can we try to simplify the if-else here? We only need to isolate aggregates for which can be partially aggregated and for which the distribution does not match.","created_at":"2016-08-21T21:30:13Z","updated_at":"2016-08-21T21:30:13Z","html_url":"https://github.com/apache/spark/pull/10896#discussion_r75603771","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/10896","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/75603771"},"html":{"href":"https://github.com/apache/spark/pull/10896#discussion_r75603771"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/10896"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/10896","id":57039592,"html_url":"https://github.com/apache/spark/pull/10896","diff_url":"https://github.com/apache/spark/pull/10896.diff","patch_url":"https://github.com/apache/spark/pull/10896.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/10896","number":10896,"state":"open","locked":false,"title":"[SPARK-12978][SQL] Skip unnecessary final group-by when input data already clustered with group-by keys","user":{"login":"maropu","id":692303,"avatar_url":"https://avatars.githubusercontent.com/u/692303?v=3","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},"body":"This ticket targets the optimization to skip an unnecessary group-by operation below;\r\n\r\nWithout opt.:\r\n```\r\n== Physical Plan ==\r\nTungstenAggregate(key=[col0#159], functions=[(sum(col1#160),mode=Final,isDistinct=false),(avg(col2#161),mode=Final,isDistinct=false)], output=[col0#159,sum(col1)#177,avg(col2)#178])\r\n+- TungstenAggregate(key=[col0#159], functions=[(sum(col1#160),mode=Partial,isDistinct=false),(avg(col2#161),mode=Partial,isDistinct=false)], output=[col0#159,sum#200,sum#201,count#202L])\r\n   +- TungstenExchange hashpartitioning(col0#159,200), None\r\n      +- InMemoryColumnarTableScan [col0#159,col1#160,col2#161], InMemoryRelation [col0#159,col1#160,col2#161], true, 10000, StorageLevel(true, true, false, true, 1), ConvertToUnsafe, None\r\n```\r\n\r\nWith opt.:\r\n```\r\n== Physical Plan ==\r\nTungstenAggregate(key=[col0#159], functions=[(sum(col1#160),mode=Complete,isDistinct=false),(avg(col2#161),mode=Final,isDistinct=false)], output=[col0#159,sum(col1)#177,avg(col2)#178])\r\n+- TungstenExchange hashpartitioning(col0#159,200), None\r\n  +- InMemoryColumnarTableScan [col0#159,col1#160,col2#161], InMemoryRelation [col0#159,col1#160,col2#161], true, 10000, StorageLevel(true, true, false, true, 1), ConvertToUnsafe, None\r\n```\r\n","created_at":"2016-01-25T08:14:25Z","updated_at":"2016-08-21T21:30:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6a487cff4cb1218d4a41d4d47233c88df99e09bb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/10896/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/10896/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/10896/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/91701eb5171555ce73ba6b190b41cc17f05eee8c","head":{"label":"maropu:SkipGroupbySpike","ref":"SkipGroupbySpike","sha":"91701eb5171555ce73ba6b190b41cc17f05eee8c","user":{"login":"maropu","id":692303,"avatar_url":"https://avatars.githubusercontent.com/u/692303?v=3","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},"repo":{"id":27115199,"name":"spark","full_name":"maropu/spark","owner":{"login":"maropu","id":692303,"avatar_url":"https://avatars.githubusercontent.com/u/692303?v=3","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},"private":false,"html_url":"https://github.com/maropu/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/maropu/spark","forks_url":"https://api.github.com/repos/maropu/spark/forks","keys_url":"https://api.github.com/repos/maropu/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/maropu/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/maropu/spark/teams","hooks_url":"https://api.github.com/repos/maropu/spark/hooks","issue_events_url":"https://api.github.com/repos/maropu/spark/issues/events{/number}","events_url":"https://api.github.com/repos/maropu/spark/events","assignees_url":"https://api.github.com/repos/maropu/spark/assignees{/user}","branches_url":"https://api.github.com/repos/maropu/spark/branches{/branch}","tags_url":"https://api.github.com/repos/maropu/spark/tags","blobs_url":"https://api.github.com/repos/maropu/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/maropu/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/maropu/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/maropu/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/maropu/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/maropu/spark/languages","stargazers_url":"https://api.github.com/repos/maropu/spark/stargazers","contributors_url":"https://api.github.com/repos/maropu/spark/contributors","subscribers_url":"https://api.github.com/repos/maropu/spark/subscribers","subscription_url":"https://api.github.com/repos/maropu/spark/subscription","commits_url":"https://api.github.com/repos/maropu/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/maropu/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/maropu/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/maropu/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/maropu/spark/contents/{+path}","compare_url":"https://api.github.com/repos/maropu/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/maropu/spark/merges","archive_url":"https://api.github.com/repos/maropu/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/maropu/spark/downloads","issues_url":"https://api.github.com/repos/maropu/spark/issues{/number}","pulls_url":"https://api.github.com/repos/maropu/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/maropu/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/maropu/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/maropu/spark/labels{/name}","releases_url":"https://api.github.com/repos/maropu/spark/releases{/id}","deployments_url":"https://api.github.com/repos/maropu/spark/deployments","created_at":"2014-11-25T08:00:37Z","updated_at":"2016-01-12T09:36:15Z","pushed_at":"2016-08-19T16:41:35Z","git_url":"git://github.com/maropu/spark.git","ssh_url":"git@github.com:maropu/spark.git","clone_url":"https://github.com/maropu/spark.git","svn_url":"https://github.com/maropu/spark","homepage":null,"size":163899,"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":"071eaaf9d2b63589f2e66e5279a16a5a484de6f5","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-08-21T19:44:55Z","pushed_at":"2016-08-21T21:03:24Z","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":509999,"stargazers_count":9726,"watchers_count":9726,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9059,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":479,"forks":9059,"open_issues":479,"watchers":9726,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/10896"},"html":{"href":"https://github.com/apache/spark/pull/10896"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/10896"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/10896/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/10896/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/10896/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/91701eb5171555ce73ba6b190b41cc17f05eee8c"}}}}
{"actor":{"display_login":"hvanhovell"}}