{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/34968726","id":34968726,"diff_hunk":"@@ -0,0 +1,237 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.sql.catalyst.expressions.aggregate2\n+\n+import org.apache.spark.sql.catalyst.dsl.expressions._\n+import org.apache.spark.sql.catalyst.errors.TreeNodeException\n+import org.apache.spark.sql.catalyst.expressions._\n+import org.apache.spark.sql.catalyst.expressions.codegen.{GeneratedExpressionCode, CodeGenContext}\n+import org.apache.spark.sql.catalyst.InternalRow\n+import org.apache.spark.sql.types._\n+\n+/** The mode of an [[AggregateFunction1]]. */\n+private[sql] sealed trait AggregateMode\n+\n+/**\n+ * An [[AggregateFunction1]] with [[Partial]] mode is used for partial aggregation.\n+ * This function updates the given aggregation buffer with the original input of this\n+ * function. When it has processed all input rows, the aggregation buffer is returned.\n+ */\n+private[sql] case object Partial extends AggregateMode\n+\n+/**\n+ * An [[AggregateFunction1]] with [[PartialMerge]] mode is used to merge aggregation buffers\n+ * containing intermediate results for this function.\n+ * This function updates the given aggregation buffer by merging multiple aggregation buffers.\n+ * When it has processed all input rows, the aggregation buffer is returned.\n+ */\n+private[sql] case object PartialMerge extends AggregateMode\n+\n+/**\n+ * An [[AggregateFunction1]] with [[PartialMerge]] mode is used to merge aggregation buffers\n+ * containing intermediate results for this function and the generate final result.\n+ * This function updates the given aggregation buffer by merging multiple aggregation buffers.\n+ * When it has processed all input rows, the final result of this function is returned.\n+ */\n+private[sql] case object Final extends AggregateMode\n+\n+/**\n+ * An [[AggregateFunction2]] with [[Partial]] mode is used to evaluate this function directly\n+ * from original input rows without any partial aggregation.\n+ * This function updates the given aggregation buffer with the original input of this\n+ * function. When it has processed all input rows, the final result of this function is returned.\n+ */\n+private[sql] case object Complete extends AggregateMode\n+\n+private[sql] case object NoOp extends Expression with Unevaluable {","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate2/aggregates.scala","position":61,"original_position":61,"commit_id":"d678aee3e1498c88c614e90240c4ce95169089a6","original_commit_id":"d678aee3e1498c88c614e90240c4ce95169089a6","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":"Will add comments to it and figure out the right place for it later.","created_at":"2015-07-20T05:07:31Z","updated_at":"2015-07-20T05:07:31Z","html_url":"https://github.com/apache/spark/pull/7458#discussion_r34968726","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/7458","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/34968726"},"html":{"href":"https://github.com/apache/spark/pull/7458#discussion_r34968726"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/7458"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/7458","id":40199174,"html_url":"https://github.com/apache/spark/pull/7458","diff_url":"https://github.com/apache/spark/pull/7458.diff","patch_url":"https://github.com/apache/spark/pull/7458.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/7458","number":7458,"state":"open","locked":false,"title":"[SPARK-4366] [SQL] [WIP] Aggregation Improvement","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-4366\r\n\r\nThis work will have a new code path for evaluating aggregate functions. To enable this path, you can set `spark.sql.useAggregate2` to true.\r\n\r\nThis WIP PR contains:\r\n* A new aggregate function interface (`AggregateFunction2`) and two example aggregate functions (`Average` and `MyDoubleSum`).\r\n* A sort-based aggregate operator for the new aggregate function interface (`Aggregate2Sort`).\r\n\r\nThere are five remaining tasks for a complete prototype.\r\n- [ ] `DISTINCT` aggregation support\r\n- [ ] UDAF interface (based on `AggregateFunction2`).\r\n- [ ] Use `ExpectsInputTypes` with `AggregateFunction2`\r\n- [ ] HiveUDAF support\r\n- [ ] Figure out the code path and necessary changes to use new aggregate functions as window functions (This is an initial investigation. The actual work can be done in a separate PR).","created_at":"2015-07-17T04:16:25Z","updated_at":"2015-07-20T05:07:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"405033c9f60f86414e5c398bb2ef0de895cea953","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/7458/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/7458/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/7458/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/d678aee3e1498c88c614e90240c4ce95169089a6","head":{"label":"yhuai:UDAF","ref":"UDAF","sha":"d678aee3e1498c88c614e90240c4ce95169089a6","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-07-20T05:06:15Z","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":112735,"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":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"163e3f1df94f6b7d3dadb46a87dbb3a2bade3f95","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-07-20T04:23:31Z","pushed_at":"2015-07-20T05:06:29Z","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":1558621,"stargazers_count":4796,"watchers_count":4796,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4292,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":335,"forks":4292,"open_issues":335,"watchers":4796,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/7458"},"html":{"href":"https://github.com/apache/spark/pull/7458"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/7458"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/7458/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/7458/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/7458/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/d678aee3e1498c88c614e90240c4ce95169089a6"}}}}