{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/33107345","id":33107345,"diff_hunk":"@@ -160,6 +159,77 @@ case class Expm1(child: Expression) extends UnaryMathExpression(math.expm1, \"EXP\n \n case class Floor(child: Expression) extends UnaryMathExpression(math.floor, \"FLOOR\")\n \n+object Factorial {\n+\n+  def factorial(n: Int): Long = {\n+    require(n >= 0, \"the input value should not be negative\")\n+    if (n < factorials.length) factorials(n) else Long.MaxValue\n+  }\n+\n+  private val factorials: Array[Long] = Array[Long](\n+    1,\n+    1,\n+    2,\n+    6,\n+    24,\n+    120,\n+    720,\n+    5040,\n+    40320,\n+    362880,\n+    3628800,\n+    39916800,\n+    479001600,\n+    6227020800L,\n+    87178291200L,\n+    1307674368000L,\n+    20922789888000L,\n+    355687428096000L,\n+    6402373705728000L,\n+    121645100408832000L,\n+    2432902008176640000L\n+  )\n+}\n+\n+case class Factorial(child: Expression)\n+  extends UnaryExpression with Serializable with ExpectsInputTypes {\n+  override def expectedChildTypes: Seq[DataType] = Seq(IntegerType)\n+  override def dataType: DataType = LongType\n+  override def foldable: Boolean = child.foldable\n+  override def nullable: Boolean = true\n+  override def toString: String = s\"factorial($child)\"\n+\n+  override def eval(input: InternalRow): Any = {\n+    val evalE = child.eval(input)\n+    if (evalE == null) {\n+      null\n+    } else {\n+      val input = evalE.asInstanceOf[Integer]\n+      if (input > 20 || input < 0) {","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/math.scala","position":61,"original_position":61,"commit_id":"9ccf803a71916639725be63f7ec7fb3aba79a22b","original_commit_id":"9ccf803a71916639725be63f7ec7fb3aba79a22b","user":{"login":"chenghao-intel","id":2367031,"avatar_url":"https://avatars.githubusercontent.com/u/2367031?v=3","gravatar_id":"","url":"https://api.github.com/users/chenghao-intel","html_url":"https://github.com/chenghao-intel","followers_url":"https://api.github.com/users/chenghao-intel/followers","following_url":"https://api.github.com/users/chenghao-intel/following{/other_user}","gists_url":"https://api.github.com/users/chenghao-intel/gists{/gist_id}","starred_url":"https://api.github.com/users/chenghao-intel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenghao-intel/subscriptions","organizations_url":"https://api.github.com/users/chenghao-intel/orgs","repos_url":"https://api.github.com/users/chenghao-intel/repos","events_url":"https://api.github.com/users/chenghao-intel/events{/privacy}","received_events_url":"https://api.github.com/users/chenghao-intel/received_events","type":"User","site_admin":false},"body":"`input>20` is also valid, and it's value should be `Long.MaxValue`, isn't it?","created_at":"2015-06-24T00:19:52Z","updated_at":"2015-06-24T00:19:52Z","html_url":"https://github.com/apache/spark/pull/6822#discussion_r33107345","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6822","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/33107345"},"html":{"href":"https://github.com/apache/spark/pull/6822#discussion_r33107345"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6822"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6822","id":37662544,"html_url":"https://github.com/apache/spark/pull/6822","diff_url":"https://github.com/apache/spark/pull/6822.diff","patch_url":"https://github.com/apache/spark/pull/6822.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6822","number":6822,"state":"open","locked":false,"title":"[SPARK-8213][SQL][WIP]Add function factorial","user":{"login":"zhichao-li","id":2662017,"avatar_url":"https://avatars.githubusercontent.com/u/2662017?v=3","gravatar_id":"","url":"https://api.github.com/users/zhichao-li","html_url":"https://github.com/zhichao-li","followers_url":"https://api.github.com/users/zhichao-li/followers","following_url":"https://api.github.com/users/zhichao-li/following{/other_user}","gists_url":"https://api.github.com/users/zhichao-li/gists{/gist_id}","starred_url":"https://api.github.com/users/zhichao-li/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhichao-li/subscriptions","organizations_url":"https://api.github.com/users/zhichao-li/orgs","repos_url":"https://api.github.com/users/zhichao-li/repos","events_url":"https://api.github.com/users/zhichao-li/events{/privacy}","received_events_url":"https://api.github.com/users/zhichao-li/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-06-15T06:50:39Z","updated_at":"2015-06-24T00:19:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c776048fd6ca55074dd6982b3f9e6527cdfa376d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6822/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6822/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6822/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/9ccf803a71916639725be63f7ec7fb3aba79a22b","head":{"label":"zhichao-li:factorial","ref":"factorial","sha":"9ccf803a71916639725be63f7ec7fb3aba79a22b","user":{"login":"zhichao-li","id":2662017,"avatar_url":"https://avatars.githubusercontent.com/u/2662017?v=3","gravatar_id":"","url":"https://api.github.com/users/zhichao-li","html_url":"https://github.com/zhichao-li","followers_url":"https://api.github.com/users/zhichao-li/followers","following_url":"https://api.github.com/users/zhichao-li/following{/other_user}","gists_url":"https://api.github.com/users/zhichao-li/gists{/gist_id}","starred_url":"https://api.github.com/users/zhichao-li/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhichao-li/subscriptions","organizations_url":"https://api.github.com/users/zhichao-li/orgs","repos_url":"https://api.github.com/users/zhichao-li/repos","events_url":"https://api.github.com/users/zhichao-li/events{/privacy}","received_events_url":"https://api.github.com/users/zhichao-li/received_events","type":"User","site_admin":false},"repo":{"id":30742930,"name":"spark","full_name":"zhichao-li/spark","owner":{"login":"zhichao-li","id":2662017,"avatar_url":"https://avatars.githubusercontent.com/u/2662017?v=3","gravatar_id":"","url":"https://api.github.com/users/zhichao-li","html_url":"https://github.com/zhichao-li","followers_url":"https://api.github.com/users/zhichao-li/followers","following_url":"https://api.github.com/users/zhichao-li/following{/other_user}","gists_url":"https://api.github.com/users/zhichao-li/gists{/gist_id}","starred_url":"https://api.github.com/users/zhichao-li/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhichao-li/subscriptions","organizations_url":"https://api.github.com/users/zhichao-li/orgs","repos_url":"https://api.github.com/users/zhichao-li/repos","events_url":"https://api.github.com/users/zhichao-li/events{/privacy}","received_events_url":"https://api.github.com/users/zhichao-li/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zhichao-li/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/zhichao-li/spark","forks_url":"https://api.github.com/repos/zhichao-li/spark/forks","keys_url":"https://api.github.com/repos/zhichao-li/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zhichao-li/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zhichao-li/spark/teams","hooks_url":"https://api.github.com/repos/zhichao-li/spark/hooks","issue_events_url":"https://api.github.com/repos/zhichao-li/spark/issues/events{/number}","events_url":"https://api.github.com/repos/zhichao-li/spark/events","assignees_url":"https://api.github.com/repos/zhichao-li/spark/assignees{/user}","branches_url":"https://api.github.com/repos/zhichao-li/spark/branches{/branch}","tags_url":"https://api.github.com/repos/zhichao-li/spark/tags","blobs_url":"https://api.github.com/repos/zhichao-li/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zhichao-li/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zhichao-li/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/zhichao-li/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zhichao-li/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/zhichao-li/spark/languages","stargazers_url":"https://api.github.com/repos/zhichao-li/spark/stargazers","contributors_url":"https://api.github.com/repos/zhichao-li/spark/contributors","subscribers_url":"https://api.github.com/repos/zhichao-li/spark/subscribers","subscription_url":"https://api.github.com/repos/zhichao-li/spark/subscription","commits_url":"https://api.github.com/repos/zhichao-li/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/zhichao-li/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/zhichao-li/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/zhichao-li/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/zhichao-li/spark/contents/{+path}","compare_url":"https://api.github.com/repos/zhichao-li/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zhichao-li/spark/merges","archive_url":"https://api.github.com/repos/zhichao-li/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zhichao-li/spark/downloads","issues_url":"https://api.github.com/repos/zhichao-li/spark/issues{/number}","pulls_url":"https://api.github.com/repos/zhichao-li/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/zhichao-li/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/zhichao-li/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zhichao-li/spark/labels{/name}","releases_url":"https://api.github.com/repos/zhichao-li/spark/releases{/id}","created_at":"2015-02-13T06:06:08Z","updated_at":"2015-04-14T06:24:38Z","pushed_at":"2015-06-23T12:30:29Z","git_url":"git://github.com/zhichao-li/spark.git","ssh_url":"git@github.com:zhichao-li/spark.git","clone_url":"https://github.com/zhichao-li/spark.git","svn_url":"https://github.com/zhichao-li/spark","homepage":null,"size":106727,"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":"754929b153aba3a8f8fbafa1581957da4ccc18be","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-06-23T21:46:48Z","pushed_at":"2015-06-24T00:18:32Z","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":1486912,"stargazers_count":4510,"watchers_count":4510,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3969,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":336,"forks":3969,"open_issues":336,"watchers":4510,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6822"},"html":{"href":"https://github.com/apache/spark/pull/6822"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6822"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6822/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6822/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6822/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/9ccf803a71916639725be63f7ec7fb3aba79a22b"}}}}