{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/42584440","id":42584440,"diff_hunk":"@@ -842,3 +699,302 @@ object HyperLogLogPlusPlus {\n   )\n   // scalastyle:on\n }\n+\n+abstract class CentralMomentAgg(child: Expression) extends ImperativeAggregate with Serializable {\n+\n+  /**\n+   * The maximum central moment order to be computed\n+   */\n+  protected def maxMoment: Int\n+\n+  override def children: Seq[Expression] = Seq(child)\n+\n+  override def nullable: Boolean = false\n+\n+  override def dataType: DataType = DoubleType\n+\n+  // Expected input data type.\n+  // TODO: Right now, we replace old aggregate functions (based on AggregateExpression1) to the\n+  // new version at planning time (after analysis phase). For now, NullType is added at here\n+  // to make it resolved when we have cases like `select avg(null)`.\n+  // We can use our analyzer to cast NullType to the default data type of the NumericType once\n+  // we remove the old aggregate functions. Then, we will not need NullType at here.\n+  override def inputTypes: Seq[AbstractDataType] = Seq(TypeCollection(NumericType, NullType))\n+\n+  override def aggBufferSchema: StructType = StructType.fromAttributes(aggBufferAttributes)\n+\n+  /**\n+   * The number of central moments to store in the buffer\n+   */\n+  private[this] val numMoments = 5\n+\n+  override val aggBufferAttributes: Seq[AttributeReference] = Seq.tabulate(numMoments) { i =>\n+    AttributeReference(s\"M$i\", DoubleType)()\n+  }\n+\n+  /**\n+   * Initialize all moments to zero\n+   */\n+  override def initialize(buffer: MutableRow): Unit = {\n+    var aggIndex = 0\n+    while (aggIndex < numMoments) {\n+      buffer.setDouble(mutableAggBufferOffset + aggIndex, 0.0)\n+      aggIndex += 1\n+    }\n+  }\n+\n+  /**\n+   * Update the central moments buffer.\n+   */\n+  override def update(buffer: MutableRow, input: InternalRow): Unit = {\n+    val v = Cast(child, DoubleType).eval(input)\n+    if (v != null) {\n+      val updateValue = v match {\n+        case d: Double => d\n+        case _ => 0.0\n+      }\n+      val currentM0 = buffer.getDouble(mutableAggBufferOffset)\n+      val currentM1 = buffer.getDouble(mutableAggBufferOffset + 1)\n+      val currentM2 = buffer.getDouble(mutableAggBufferOffset + 2)\n+      val currentM3 = buffer.getDouble(mutableAggBufferOffset + 3)","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/functions.scala","position":null,"original_position":211,"commit_id":"62c515cad1e2fb712256601f139d098fa4fb3749","original_commit_id":"b180a2857716ccf0e7c32d5aca0417f5a515d2cb","user":{"login":"sethah","id":7275795,"avatar_url":"https://avatars.githubusercontent.com/u/7275795?v=3","gravatar_id":"","url":"https://api.github.com/users/sethah","html_url":"https://github.com/sethah","followers_url":"https://api.github.com/users/sethah/followers","following_url":"https://api.github.com/users/sethah/following{/other_user}","gists_url":"https://api.github.com/users/sethah/gists{/gist_id}","starred_url":"https://api.github.com/users/sethah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethah/subscriptions","organizations_url":"https://api.github.com/users/sethah/orgs","repos_url":"https://api.github.com/users/sethah/repos","events_url":"https://api.github.com/users/sethah/events{/privacy}","received_events_url":"https://api.github.com/users/sethah/received_events","type":"User","site_admin":false},"body":"moved unnecessary gets and sets into if statements","created_at":"2015-10-21T05:28:29Z","updated_at":"2015-10-21T05:28:29Z","html_url":"https://github.com/apache/spark/pull/9003#discussion_r42584440","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/9003","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/42584440"},"html":{"href":"https://github.com/apache/spark/pull/9003#discussion_r42584440"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/9003"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/9003","id":46958902,"html_url":"https://github.com/apache/spark/pull/9003","diff_url":"https://github.com/apache/spark/pull/9003.diff","patch_url":"https://github.com/apache/spark/pull/9003.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/9003","number":9003,"state":"open","locked":false,"title":"[SPARK-10641][WIP][SQL] Add Skewness and Kurtosis Support","user":{"login":"sethah","id":7275795,"avatar_url":"https://avatars.githubusercontent.com/u/7275795?v=3","gravatar_id":"","url":"https://api.github.com/users/sethah","html_url":"https://github.com/sethah","followers_url":"https://api.github.com/users/sethah/followers","following_url":"https://api.github.com/users/sethah/following{/other_user}","gists_url":"https://api.github.com/users/sethah/gists{/gist_id}","starred_url":"https://api.github.com/users/sethah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethah/subscriptions","organizations_url":"https://api.github.com/users/sethah/orgs","repos_url":"https://api.github.com/users/sethah/repos","events_url":"https://api.github.com/users/sethah/events{/privacy}","received_events_url":"https://api.github.com/users/sethah/received_events","type":"User","site_admin":false},"body":"Implementing skewness and kurtosis support based on following algorithm:\r\nhttps://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Higher-order_statistics\r\n","created_at":"2015-10-06T21:15:56Z","updated_at":"2015-10-21T05:28:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"797c40f77e94a636dc8811c71f4855066a3ea0ef","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/9003/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/9003/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/9003/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/62c515cad1e2fb712256601f139d098fa4fb3749","head":{"label":"sethah:SPARK-10641","ref":"SPARK-10641","sha":"62c515cad1e2fb712256601f139d098fa4fb3749","user":{"login":"sethah","id":7275795,"avatar_url":"https://avatars.githubusercontent.com/u/7275795?v=3","gravatar_id":"","url":"https://api.github.com/users/sethah","html_url":"https://github.com/sethah","followers_url":"https://api.github.com/users/sethah/followers","following_url":"https://api.github.com/users/sethah/following{/other_user}","gists_url":"https://api.github.com/users/sethah/gists{/gist_id}","starred_url":"https://api.github.com/users/sethah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethah/subscriptions","organizations_url":"https://api.github.com/users/sethah/orgs","repos_url":"https://api.github.com/users/sethah/repos","events_url":"https://api.github.com/users/sethah/events{/privacy}","received_events_url":"https://api.github.com/users/sethah/received_events","type":"User","site_admin":false},"repo":{"id":38016887,"name":"spark","full_name":"sethah/spark","owner":{"login":"sethah","id":7275795,"avatar_url":"https://avatars.githubusercontent.com/u/7275795?v=3","gravatar_id":"","url":"https://api.github.com/users/sethah","html_url":"https://github.com/sethah","followers_url":"https://api.github.com/users/sethah/followers","following_url":"https://api.github.com/users/sethah/following{/other_user}","gists_url":"https://api.github.com/users/sethah/gists{/gist_id}","starred_url":"https://api.github.com/users/sethah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sethah/subscriptions","organizations_url":"https://api.github.com/users/sethah/orgs","repos_url":"https://api.github.com/users/sethah/repos","events_url":"https://api.github.com/users/sethah/events{/privacy}","received_events_url":"https://api.github.com/users/sethah/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sethah/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/sethah/spark","forks_url":"https://api.github.com/repos/sethah/spark/forks","keys_url":"https://api.github.com/repos/sethah/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sethah/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sethah/spark/teams","hooks_url":"https://api.github.com/repos/sethah/spark/hooks","issue_events_url":"https://api.github.com/repos/sethah/spark/issues/events{/number}","events_url":"https://api.github.com/repos/sethah/spark/events","assignees_url":"https://api.github.com/repos/sethah/spark/assignees{/user}","branches_url":"https://api.github.com/repos/sethah/spark/branches{/branch}","tags_url":"https://api.github.com/repos/sethah/spark/tags","blobs_url":"https://api.github.com/repos/sethah/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sethah/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sethah/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/sethah/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sethah/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/sethah/spark/languages","stargazers_url":"https://api.github.com/repos/sethah/spark/stargazers","contributors_url":"https://api.github.com/repos/sethah/spark/contributors","subscribers_url":"https://api.github.com/repos/sethah/spark/subscribers","subscription_url":"https://api.github.com/repos/sethah/spark/subscription","commits_url":"https://api.github.com/repos/sethah/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/sethah/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/sethah/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/sethah/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/sethah/spark/contents/{+path}","compare_url":"https://api.github.com/repos/sethah/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sethah/spark/merges","archive_url":"https://api.github.com/repos/sethah/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sethah/spark/downloads","issues_url":"https://api.github.com/repos/sethah/spark/issues{/number}","pulls_url":"https://api.github.com/repos/sethah/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/sethah/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/sethah/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sethah/spark/labels{/name}","releases_url":"https://api.github.com/repos/sethah/spark/releases{/id}","created_at":"2015-06-24T23:36:53Z","updated_at":"2015-06-24T23:37:41Z","pushed_at":"2015-10-21T05:26:34Z","git_url":"git://github.com/sethah/spark.git","ssh_url":"git@github.com:sethah/spark.git","clone_url":"https://github.com/sethah/spark.git","svn_url":"https://github.com/sethah/spark","homepage":null,"size":125819,"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":"1107bd958aefc793d6e8e369ad6268b24a0f8510","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-10-21T05:20:09Z","pushed_at":"2015-10-21T05:27:51Z","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":1638064,"stargazers_count":5823,"watchers_count":5823,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5427,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":319,"forks":5427,"open_issues":319,"watchers":5823,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/9003"},"html":{"href":"https://github.com/apache/spark/pull/9003"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/9003"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/9003/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/9003/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/9003/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/62c515cad1e2fb712256601f139d098fa4fb3749"}}}}