{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/29107408","id":29107408,"diff_hunk":"@@ -0,0 +1,215 @@\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\n+\n+import org.apache.spark.sql.catalyst.analysis.UnresolvedException\n+import org.apache.spark.sql.types._\n+\n+abstract class MathematicalExpression(name: String) extends UnaryExpression with Serializable { \n+  self: Product =>\n+  type EvaluatedType = Any\n+\n+  override def dataType: DataType = DoubleType\n+  override def foldable: Boolean = child.foldable\n+  override def nullable: Boolean = true\n+  override def toString: String = s\"$name($child)\"\n+\n+  lazy val numeric = child.dataType match {\n+    case n: NumericType => n.numeric.asInstanceOf[Numeric[Any]]\n+    case other => sys.error(s\"Type $other does not support numeric operations\")\n+  }\n+}\n+\n+abstract class MathematicalExpressionForDouble(f: Double => Double, name: String)\n+  extends MathematicalExpression(name) { self: Product =>\n+  override def eval(input: Row): Any = {\n+    val evalE = child.eval(input)\n+    if (evalE == null) {\n+      null\n+    } else {\n+      val result = f(numeric.toDouble(evalE)) \n+      if (result.isNaN) null\n+      else result\n+    }\n+  }\n+}\n+\n+abstract class MathematicalExpressionForInt(f: Int => Int, name: String)\n+  extends MathematicalExpression(name) { self: Product =>\n+  override def dataType: DataType = IntegerType\n+\n+  override def eval(input: Row): Any = {\n+    val evalE = child.eval(input)\n+    if (evalE == null) {\n+      null\n+    } else {\n+      f(numeric.toInt(evalE))\n+    }\n+  }\n+}\n+\n+abstract class MathematicalExpressionForFloat(f: Float => Float, name: String)\n+  extends MathematicalExpression(name) { self: Product =>\n+\n+  override def dataType: DataType = FloatType\n+\n+  override def eval(input: Row): Any = {\n+    val evalE = child.eval(input)\n+    if (evalE == null) {\n+      null\n+    } else {\n+      val result = f(numeric.toFloat(evalE))\n+      if (result.isNaN) null\n+      else result\n+    }\n+  }\n+}\n+\n+abstract class MathematicalExpressionForLong(f: Long => Long, name: String)\n+  extends MathematicalExpression(name) { self: Product =>\n+\n+  override def dataType: DataType = LongType\n+\n+  override def eval(input: Row): Any = {\n+    val evalE = child.eval(input)\n+    if (evalE == null) {\n+      null\n+    } else {\n+      f(numeric.toLong(evalE))\n+    }\n+  }\n+}\n+\n+case class Sin(child: Expression) extends MathematicalExpressionForDouble(math.sin, \"SIN\")\n+\n+case class Asin(child: Expression) extends MathematicalExpressionForDouble(math.asin, \"ASIN\")\n+\n+case class Sinh(child: Expression) extends MathematicalExpressionForDouble(math.sinh, \"SINH\")\n+\n+case class Cos(child: Expression) extends MathematicalExpressionForDouble(math.cos, \"COS\")\n+\n+case class Acos(child: Expression) extends MathematicalExpressionForDouble(math.acos, \"ACOS\")\n+\n+case class Cosh(child: Expression) extends MathematicalExpressionForDouble(math.cosh, \"COSH\")\n+\n+case class Tan(child: Expression) extends MathematicalExpressionForDouble(math.tan, \"TAN\")\n+\n+case class Atan(child: Expression) extends MathematicalExpressionForDouble(math.atan, \"ATAN\")\n+\n+case class Tanh(child: Expression) extends MathematicalExpressionForDouble(math.tanh, \"TANH\")\n+\n+case class Ceil(child: Expression) extends MathematicalExpressionForDouble(math.ceil, \"CEIL\")\n+\n+case class Floor(child: Expression) extends MathematicalExpressionForDouble(math.floor, \"FLOOR\")\n+\n+case class Rint(child: Expression) extends MathematicalExpressionForDouble(math.rint, \"ROUND\")\n+\n+case class Cbrt(child: Expression) extends MathematicalExpressionForDouble(math.cbrt, \"CBRT\")\n+\n+case class Signum(child: Expression) extends MathematicalExpressionForDouble(math.signum, \"SIGNUM\")\n+\n+case class ISignum(child: Expression) extends MathematicalExpressionForInt(math.signum, \"ISIGNUM\")\n+\n+case class FSignum(child: Expression) extends MathematicalExpressionForFloat(math.signum, \"FSIGNUM\")\n+\n+case class LSignum(child: Expression) extends MathematicalExpressionForLong(math.signum, \"LSIGNUM\")\n+\n+case class ToDegrees(child: Expression) \n+  extends MathematicalExpressionForDouble(math.toDegrees, \"DEGREES\")\n+\n+case class ToRadians(child: Expression) \n+  extends MathematicalExpressionForDouble(math.toRadians, \"RADIANS\")\n+\n+case class Log(child: Expression) extends MathematicalExpressionForDouble(math.log, \"LOG\")\n+\n+case class Log10(child: Expression) extends MathematicalExpressionForDouble(math.log10, \"LOG10\")\n+\n+case class Log1p(child: Expression) extends MathematicalExpressionForDouble(math.log1p, \"LOG1P\")\n+\n+case class Exp(child: Expression) extends MathematicalExpressionForDouble(math.exp, \"EXP\")\n+\n+case class Expm1(child: Expression) extends MathematicalExpressionForDouble(math.expm1, \"EXPM1\")\n+\n+abstract class BinaryMathExpression(f: (Double, Double) => Double, name: String) \n+  extends BinaryFunctionExpression with Serializable { self: Product =>\n+  type EvaluatedType = Any\n+\n+  def nullable: Boolean = left.nullable || right.nullable","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathfunctions.scala","position":152,"original_position":152,"commit_id":"029e739cfad92e565c465e9e2655c59be2263c32","original_commit_id":"029e739cfad92e565c465e9e2655c59be2263c32","user":{"login":"rxin","id":323388,"avatar_url":"https://avatars.githubusercontent.com/u/323388?v=3","gravatar_id":"","url":"https://api.github.com/users/rxin","html_url":"https://github.com/rxin","followers_url":"https://api.github.com/users/rxin/followers","following_url":"https://api.github.com/users/rxin/following{/other_user}","gists_url":"https://api.github.com/users/rxin/gists{/gist_id}","starred_url":"https://api.github.com/users/rxin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rxin/subscriptions","organizations_url":"https://api.github.com/users/rxin/orgs","repos_url":"https://api.github.com/users/rxin/repos","events_url":"https://api.github.com/users/rxin/events{/privacy}","received_events_url":"https://api.github.com/users/rxin/received_events","type":"User","site_admin":false},"body":"override","created_at":"2015-04-26T07:34:59Z","updated_at":"2015-04-26T07:34:59Z","html_url":"https://github.com/apache/spark/pull/5616#discussion_r29107408","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/5616","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/29107408"},"html":{"href":"https://github.com/apache/spark/pull/5616#discussion_r29107408"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/5616"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/5616","id":33792242,"html_url":"https://github.com/apache/spark/pull/5616","diff_url":"https://github.com/apache/spark/pull/5616.diff","patch_url":"https://github.com/apache/spark/pull/5616.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/5616","number":5616,"state":"open","locked":false,"title":"[SPARK-6829] Added math functions for DataFrames","user":{"login":"brkyvz","id":5243515,"avatar_url":"https://avatars.githubusercontent.com/u/5243515?v=3","gravatar_id":"","url":"https://api.github.com/users/brkyvz","html_url":"https://github.com/brkyvz","followers_url":"https://api.github.com/users/brkyvz/followers","following_url":"https://api.github.com/users/brkyvz/following{/other_user}","gists_url":"https://api.github.com/users/brkyvz/gists{/gist_id}","starred_url":"https://api.github.com/users/brkyvz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brkyvz/subscriptions","organizations_url":"https://api.github.com/users/brkyvz/orgs","repos_url":"https://api.github.com/users/brkyvz/repos","events_url":"https://api.github.com/users/brkyvz/events{/privacy}","received_events_url":"https://api.github.com/users/brkyvz/received_events","type":"User","site_admin":false},"body":"Implemented almost all math functions found in scala.math (max, min and abs were already present).\r\n\r\ncc @mengxr @marmbrus\r\n","created_at":"2015-04-21T18:58:32Z","updated_at":"2015-04-26T07:34:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c2c15b4f6372e0a96622199203ff483c7c4bf907","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/5616/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/5616/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/5616/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/029e739cfad92e565c465e9e2655c59be2263c32","head":{"label":"brkyvz:math-udfs","ref":"math-udfs","sha":"029e739cfad92e565c465e9e2655c59be2263c32","user":{"login":"brkyvz","id":5243515,"avatar_url":"https://avatars.githubusercontent.com/u/5243515?v=3","gravatar_id":"","url":"https://api.github.com/users/brkyvz","html_url":"https://github.com/brkyvz","followers_url":"https://api.github.com/users/brkyvz/followers","following_url":"https://api.github.com/users/brkyvz/following{/other_user}","gists_url":"https://api.github.com/users/brkyvz/gists{/gist_id}","starred_url":"https://api.github.com/users/brkyvz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brkyvz/subscriptions","organizations_url":"https://api.github.com/users/brkyvz/orgs","repos_url":"https://api.github.com/users/brkyvz/repos","events_url":"https://api.github.com/users/brkyvz/events{/privacy}","received_events_url":"https://api.github.com/users/brkyvz/received_events","type":"User","site_admin":false},"repo":{"id":21919521,"name":"spark","full_name":"brkyvz/spark","owner":{"login":"brkyvz","id":5243515,"avatar_url":"https://avatars.githubusercontent.com/u/5243515?v=3","gravatar_id":"","url":"https://api.github.com/users/brkyvz","html_url":"https://github.com/brkyvz","followers_url":"https://api.github.com/users/brkyvz/followers","following_url":"https://api.github.com/users/brkyvz/following{/other_user}","gists_url":"https://api.github.com/users/brkyvz/gists{/gist_id}","starred_url":"https://api.github.com/users/brkyvz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brkyvz/subscriptions","organizations_url":"https://api.github.com/users/brkyvz/orgs","repos_url":"https://api.github.com/users/brkyvz/repos","events_url":"https://api.github.com/users/brkyvz/events{/privacy}","received_events_url":"https://api.github.com/users/brkyvz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/brkyvz/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/brkyvz/spark","forks_url":"https://api.github.com/repos/brkyvz/spark/forks","keys_url":"https://api.github.com/repos/brkyvz/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brkyvz/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brkyvz/spark/teams","hooks_url":"https://api.github.com/repos/brkyvz/spark/hooks","issue_events_url":"https://api.github.com/repos/brkyvz/spark/issues/events{/number}","events_url":"https://api.github.com/repos/brkyvz/spark/events","assignees_url":"https://api.github.com/repos/brkyvz/spark/assignees{/user}","branches_url":"https://api.github.com/repos/brkyvz/spark/branches{/branch}","tags_url":"https://api.github.com/repos/brkyvz/spark/tags","blobs_url":"https://api.github.com/repos/brkyvz/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brkyvz/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brkyvz/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/brkyvz/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brkyvz/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/brkyvz/spark/languages","stargazers_url":"https://api.github.com/repos/brkyvz/spark/stargazers","contributors_url":"https://api.github.com/repos/brkyvz/spark/contributors","subscribers_url":"https://api.github.com/repos/brkyvz/spark/subscribers","subscription_url":"https://api.github.com/repos/brkyvz/spark/subscription","commits_url":"https://api.github.com/repos/brkyvz/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/brkyvz/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/brkyvz/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/brkyvz/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/brkyvz/spark/contents/{+path}","compare_url":"https://api.github.com/repos/brkyvz/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brkyvz/spark/merges","archive_url":"https://api.github.com/repos/brkyvz/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brkyvz/spark/downloads","issues_url":"https://api.github.com/repos/brkyvz/spark/issues{/number}","pulls_url":"https://api.github.com/repos/brkyvz/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/brkyvz/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/brkyvz/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brkyvz/spark/labels{/name}","releases_url":"https://api.github.com/repos/brkyvz/spark/releases{/id}","created_at":"2014-07-16T21:51:06Z","updated_at":"2015-04-17T21:48:54Z","pushed_at":"2015-04-22T21:34:59Z","git_url":"git://github.com/brkyvz/spark.git","ssh_url":"git@github.com:brkyvz/spark.git","clone_url":"https://github.com/brkyvz/spark.git","svn_url":"https://github.com/brkyvz/spark","homepage":null,"size":97424,"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":"c035c0f2d72f2a303b86fe0037ec43d756fff060","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-04-26T03:20:11Z","pushed_at":"2015-04-26T06:41:47Z","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":1562156,"stargazers_count":3745,"watchers_count":3745,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3262,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":307,"forks":3262,"open_issues":307,"watchers":3745,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/5616"},"html":{"href":"https://github.com/apache/spark/pull/5616"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/5616"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/5616/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/5616/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/5616/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/029e739cfad92e565c465e9e2655c59be2263c32"}}}}