{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/44361188","id":44361188,"diff_hunk":"@@ -141,40 +141,56 @@ class WindowSpec private[sql](\n    */\n   private[sql] def withAggregate(aggregate: Column): Column = {\n     val windowExpr = aggregate.expr match {\n-      case Average(child) => WindowExpression(\n-        UnresolvedWindowFunction(\"avg\", child :: Nil),\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n-      case Sum(child) => WindowExpression(\n-        UnresolvedWindowFunction(\"sum\", child :: Nil),\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n-      case Count(child) => WindowExpression(\n-        UnresolvedWindowFunction(\"count\", child :: Nil),\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n-      case First(child, ignoreNulls) => WindowExpression(\n-        // TODO this is a hack for Hive UDAF first_value\n-        UnresolvedWindowFunction(\n-          \"first_value\",\n-          child :: ignoreNulls :: Nil),\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n-      case Last(child, ignoreNulls) => WindowExpression(\n-        // TODO this is a hack for Hive UDAF last_value\n-        UnresolvedWindowFunction(\n-          \"last_value\",\n-          child :: ignoreNulls :: Nil),\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n-      case Min(child) => WindowExpression(\n-        UnresolvedWindowFunction(\"min\", child :: Nil),\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n-      case Max(child) => WindowExpression(\n-        UnresolvedWindowFunction(\"max\", child :: Nil),\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n-      case wf: WindowFunction => WindowExpression(\n-        wf,\n-        WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+      // First, we check if we get an aggregate function without the DISTINCT keyword.\n+      // Right now, we do not support using a DISTINCT aggregate function as a\n+      // window function.\n+      case AggregateExpression(aggregateFunction, _, isDistinct) if !isDistinct =>\n+        aggregateFunction match {\n+          case Average(child) => WindowExpression(\n+            UnresolvedWindowFunction(\"avg\", child :: Nil),\n+            WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+          case Sum(child) => WindowExpression(\n+            UnresolvedWindowFunction(\"sum\", child :: Nil),\n+            WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+          case Count(child) => WindowExpression(\n+            UnresolvedWindowFunction(\"count\", child :: Nil),\n+            WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+          case First(child, ignoreNulls) => WindowExpression(\n+            // TODO this is a hack for Hive UDAF first_value\n+            UnresolvedWindowFunction(\n+              \"first_value\",\n+              child :: ignoreNulls :: Nil),\n+            WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+          case Last(child, ignoreNulls) => WindowExpression(\n+            // TODO this is a hack for Hive UDAF last_value\n+            UnresolvedWindowFunction(\n+              \"last_value\",\n+              child :: ignoreNulls :: Nil),\n+            WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+          case Min(child) => WindowExpression(\n+            UnresolvedWindowFunction(\"min\", child :: Nil),\n+            WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+          case Max(child) => WindowExpression(\n+            UnresolvedWindowFunction(\"max\", child :: Nil),\n+            WindowSpecDefinition(partitionSpec, orderSpec, frame))\n+          case x =>\n+            throw new UnsupportedOperationException(s\"$x is not supported in window operation.\")","path":"sql/core/src/main/scala/org/apache/spark/sql/expressions/WindowSpec.scala","position":78,"original_position":78,"commit_id":"302edac03296832a72ba944e484974f5f71b68f2","original_commit_id":"302edac03296832a72ba944e484974f5f71b68f2","user":{"login":"yhuai","id":2072857,"avatar_url":"https://avatars.githubusercontent.com/u/2072857?v=3","gravatar_id":"","url":"https://api.github.com/users/yhuai","html_url":"https://github.com/yhuai","followers_url":"https://api.github.com/users/yhuai/followers","following_url":"https://api.github.com/users/yhuai/following{/other_user}","gists_url":"https://api.github.com/users/yhuai/gists{/gist_id}","starred_url":"https://api.github.com/users/yhuai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yhuai/subscriptions","organizations_url":"https://api.github.com/users/yhuai/orgs","repos_url":"https://api.github.com/users/yhuai/repos","events_url":"https://api.github.com/users/yhuai/events{/privacy}","received_events_url":"https://api.github.com/users/yhuai/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2015-11-10T01:46:54Z","updated_at":"2015-11-10T01:46:54Z","html_url":"https://github.com/apache/spark/pull/9556#discussion_r44361188","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/9556","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/44361188"},"html":{"href":"https://github.com/apache/spark/pull/9556#discussion_r44361188"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/9556"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/9556","id":50084645,"html_url":"https://github.com/apache/spark/pull/9556","diff_url":"https://github.com/apache/spark/pull/9556.diff","patch_url":"https://github.com/apache/spark/pull/9556.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/9556","number":9556,"state":"open","locked":false,"title":"[SPARK-9830] [SQL] Remove AggregateExpression1 and Aggregate Operator used to evaluate AggregateExpression1s","user":{"login":"yhuai","id":2072857,"avatar_url":"https://avatars.githubusercontent.com/u/2072857?v=3","gravatar_id":"","url":"https://api.github.com/users/yhuai","html_url":"https://github.com/yhuai","followers_url":"https://api.github.com/users/yhuai/followers","following_url":"https://api.github.com/users/yhuai/following{/other_user}","gists_url":"https://api.github.com/users/yhuai/gists{/gist_id}","starred_url":"https://api.github.com/users/yhuai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yhuai/subscriptions","organizations_url":"https://api.github.com/users/yhuai/orgs","repos_url":"https://api.github.com/users/yhuai/repos","events_url":"https://api.github.com/users/yhuai/events{/privacy}","received_events_url":"https://api.github.com/users/yhuai/received_events","type":"User","site_admin":false},"body":"https://issues.apache.org/jira/browse/SPARK-9830\r\n\r\nThis PR contains the following main changes. \r\n* Removing `AggregateExpression1`.\r\n* Removing `Aggregate` operator, which is used to evaluate `AggregateExpression1`.\r\n* Removing planner rule used to plan `Aggregate`.\r\n* Linking `MultipleDistinctRewriter` to analyzer.\r\n* Renaming `AggregateExpression2` to `AggregateExpression` and `AggregateFunction2` to `AggregateFunction`.\r\n* Updating places where we create aggregate expression. The way to create aggregate expressions is `AggregateExpression(aggregateFunction, mode, isDistinct)`.\r\n* Changing `val`s in `DeclarativeAggregate`s that touch children of this function to `lazy val`s (when we create aggregate expression in DataFrame API, children of an aggregate function can be unresolved).","created_at":"2015-11-09T04:48:50Z","updated_at":"2015-11-10T01:46:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3135933aaac24f794787c97691f7fc96f5b620f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/9556/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/9556/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/9556/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/302edac03296832a72ba944e484974f5f71b68f2","head":{"label":"yhuai:removeAgg1","ref":"removeAgg1","sha":"302edac03296832a72ba944e484974f5f71b68f2","user":{"login":"yhuai","id":2072857,"avatar_url":"https://avatars.githubusercontent.com/u/2072857?v=3","gravatar_id":"","url":"https://api.github.com/users/yhuai","html_url":"https://github.com/yhuai","followers_url":"https://api.github.com/users/yhuai/followers","following_url":"https://api.github.com/users/yhuai/following{/other_user}","gists_url":"https://api.github.com/users/yhuai/gists{/gist_id}","starred_url":"https://api.github.com/users/yhuai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yhuai/subscriptions","organizations_url":"https://api.github.com/users/yhuai/orgs","repos_url":"https://api.github.com/users/yhuai/repos","events_url":"https://api.github.com/users/yhuai/events{/privacy}","received_events_url":"https://api.github.com/users/yhuai/received_events","type":"User","site_admin":false},"repo":{"id":17964653,"name":"spark","full_name":"yhuai/spark","owner":{"login":"yhuai","id":2072857,"avatar_url":"https://avatars.githubusercontent.com/u/2072857?v=3","gravatar_id":"","url":"https://api.github.com/users/yhuai","html_url":"https://github.com/yhuai","followers_url":"https://api.github.com/users/yhuai/followers","following_url":"https://api.github.com/users/yhuai/following{/other_user}","gists_url":"https://api.github.com/users/yhuai/gists{/gist_id}","starred_url":"https://api.github.com/users/yhuai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yhuai/subscriptions","organizations_url":"https://api.github.com/users/yhuai/orgs","repos_url":"https://api.github.com/users/yhuai/repos","events_url":"https://api.github.com/users/yhuai/events{/privacy}","received_events_url":"https://api.github.com/users/yhuai/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yhuai/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/yhuai/spark","forks_url":"https://api.github.com/repos/yhuai/spark/forks","keys_url":"https://api.github.com/repos/yhuai/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yhuai/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yhuai/spark/teams","hooks_url":"https://api.github.com/repos/yhuai/spark/hooks","issue_events_url":"https://api.github.com/repos/yhuai/spark/issues/events{/number}","events_url":"https://api.github.com/repos/yhuai/spark/events","assignees_url":"https://api.github.com/repos/yhuai/spark/assignees{/user}","branches_url":"https://api.github.com/repos/yhuai/spark/branches{/branch}","tags_url":"https://api.github.com/repos/yhuai/spark/tags","blobs_url":"https://api.github.com/repos/yhuai/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yhuai/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yhuai/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/yhuai/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yhuai/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/yhuai/spark/languages","stargazers_url":"https://api.github.com/repos/yhuai/spark/stargazers","contributors_url":"https://api.github.com/repos/yhuai/spark/contributors","subscribers_url":"https://api.github.com/repos/yhuai/spark/subscribers","subscription_url":"https://api.github.com/repos/yhuai/spark/subscription","commits_url":"https://api.github.com/repos/yhuai/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/yhuai/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/yhuai/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/yhuai/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/yhuai/spark/contents/{+path}","compare_url":"https://api.github.com/repos/yhuai/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yhuai/spark/merges","archive_url":"https://api.github.com/repos/yhuai/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yhuai/spark/downloads","issues_url":"https://api.github.com/repos/yhuai/spark/issues{/number}","pulls_url":"https://api.github.com/repos/yhuai/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/yhuai/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/yhuai/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yhuai/spark/labels{/name}","releases_url":"https://api.github.com/repos/yhuai/spark/releases{/id}","created_at":"2014-03-21T01:38:52Z","updated_at":"2015-05-07T05:56:12Z","pushed_at":"2015-11-09T23:08:26Z","git_url":"git://github.com/yhuai/spark.git","ssh_url":"git@github.com:yhuai/spark.git","clone_url":"https://github.com/yhuai/spark.git","svn_url":"https://github.com/yhuai/spark","homepage":null,"size":131935,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"b541b31630b1b85b48d6096079d073ccf46a62e8","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-11-10T00:23:33Z","pushed_at":"2015-11-10T01:44:49Z","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":1654481,"stargazers_count":6097,"watchers_count":6097,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5657,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":367,"forks":5657,"open_issues":367,"watchers":6097,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/9556"},"html":{"href":"https://github.com/apache/spark/pull/9556"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/9556"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/9556/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/9556/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/9556/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/302edac03296832a72ba944e484974f5f71b68f2"}}}}