{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/31990468","id":31990468,"diff_hunk":"@@ -32,9 +38,94 @@ trait FunctionRegistry {\n   def conf: CatalystConf\n }\n \n+\n+object FunctionRegistry {\n+\n+  type FunctionBuilder = Seq[Expression] => Expression\n+\n+  val expressions: Map[String, FunctionBuilder] = Map(\n+    // Non aggregate functions\n+    expression[Abs](\"abs\"),\n+    expression[CreateArray](\"array\"),\n+    expression[Coalesce](\"coalesce\"),\n+    expression[Explode](\"explode\"),\n+    expression[Lower](\"lower\"),\n+    expression[Substring](\"substr\"),\n+    expression[Substring](\"substring\"),\n+    expression[Rand](\"rand\"),\n+    expression[Randn](\"randn\"),\n+    expression[CreateStruct](\"struct\"),\n+    expression[Sqrt](\"sqrt\"),\n+    expression[Upper](\"upper\"),\n+\n+    // Math functions\n+    expression[Acos](\"acos\"),\n+    expression[Asin](\"asin\"),\n+    expression[Atan](\"atan\"),\n+    expression[Atan2](\"atan2\"),\n+    expression[Cbrt](\"cbrt\"),\n+    expression[Ceil](\"ceil\"),\n+    expression[Cos](\"cos\"),\n+    expression[Exp](\"exp\"),\n+    expression[Expm1](\"expm1\"),\n+    expression[Floor](\"floor\"),\n+    expression[Hypot](\"hypot\"),\n+    expression[Log](\"log\"),\n+    expression[Log10](\"log10\"),\n+    expression[Log1p](\"log1p\"),\n+    expression[Pow](\"pow\"),\n+    expression[Rint](\"rint\"),\n+    expression[Signum](\"signum\"),\n+    expression[Sin](\"sin\"),\n+    expression[Sinh](\"sinh\"),\n+    expression[Tan](\"tan\"),\n+    expression[Tanh](\"tanh\"),\n+    expression[ToDegrees](\"todegrees\"),\n+    expression[ToRadians](\"toradians\"),\n+\n+    // aggregate functions\n+    expression[Average](\"avg\"),\n+    expression[Count](\"count\"),\n+    expression[First](\"first\"),\n+    expression[Last](\"last\"),\n+    expression[Max](\"max\"),\n+    expression[Min](\"min\"),\n+    expression[Sum](\"sum\")\n+  )\n+\n+  /** See usage above. */\n+  private def expression[T <: Expression](name: String)","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala","position":140,"original_position":83,"commit_id":"69308222d1b65bd75c3b40b1e4da8f6161958535","original_commit_id":"77b46f18c9a563f0673ddf097bf1e08c7be0ca1d","user":{"login":"liancheng","id":230655,"avatar_url":"https://avatars.githubusercontent.com/u/230655?v=3","gravatar_id":"","url":"https://api.github.com/users/liancheng","html_url":"https://github.com/liancheng","followers_url":"https://api.github.com/users/liancheng/followers","following_url":"https://api.github.com/users/liancheng/following{/other_user}","gists_url":"https://api.github.com/users/liancheng/gists{/gist_id}","starred_url":"https://api.github.com/users/liancheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liancheng/subscriptions","organizations_url":"https://api.github.com/users/liancheng/orgs","repos_url":"https://api.github.com/users/liancheng/repos","events_url":"https://api.github.com/users/liancheng/events{/privacy}","received_events_url":"https://api.github.com/users/liancheng/received_events","type":"User","site_admin":false},"body":"Should we remove the `name` argument? Seems that we are just using `classOf[T].getName.stripSuffix(\"$\").toLowerCase` for `name`.","created_at":"2015-06-09T08:07:03Z","updated_at":"2015-06-09T08:07:03Z","html_url":"https://github.com/apache/spark/pull/6710#discussion_r31990468","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6710","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/31990468"},"html":{"href":"https://github.com/apache/spark/pull/6710#discussion_r31990468"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6710"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6710","id":37206371,"html_url":"https://github.com/apache/spark/pull/6710","diff_url":"https://github.com/apache/spark/pull/6710.diff","patch_url":"https://github.com/apache/spark/pull/6710.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6710","number":6710,"state":"open","locked":false,"title":"[SPARK-7886] Add built-in expressions to FunctionRegistry.","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":"This patch switches to using FunctionRegistry for built-in expressions. It is based on #6463, but with some work to simplify it along with unit tests.\r\n\r\nTODOs for future pull requests:\r\n- Use static registration so we don't need to register all functions every time we start a new SQLContext\r\n- Switch to using this in HiveContext\r\n","created_at":"2015-06-08T23:25:24Z","updated_at":"2015-06-09T08:07:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"773631f9bcfa3947f00b5813f957c186d76e2b22","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6710/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6710/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6710/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/69308222d1b65bd75c3b40b1e4da8f6161958535","head":{"label":"rxin:udf-registry","ref":"udf-registry","sha":"69308222d1b65bd75c3b40b1e4da8f6161958535","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},"repo":{"id":17192644,"name":"spark","full_name":"rxin/spark","owner":{"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},"private":false,"html_url":"https://github.com/rxin/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/rxin/spark","forks_url":"https://api.github.com/repos/rxin/spark/forks","keys_url":"https://api.github.com/repos/rxin/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rxin/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rxin/spark/teams","hooks_url":"https://api.github.com/repos/rxin/spark/hooks","issue_events_url":"https://api.github.com/repos/rxin/spark/issues/events{/number}","events_url":"https://api.github.com/repos/rxin/spark/events","assignees_url":"https://api.github.com/repos/rxin/spark/assignees{/user}","branches_url":"https://api.github.com/repos/rxin/spark/branches{/branch}","tags_url":"https://api.github.com/repos/rxin/spark/tags","blobs_url":"https://api.github.com/repos/rxin/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rxin/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rxin/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/rxin/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rxin/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/rxin/spark/languages","stargazers_url":"https://api.github.com/repos/rxin/spark/stargazers","contributors_url":"https://api.github.com/repos/rxin/spark/contributors","subscribers_url":"https://api.github.com/repos/rxin/spark/subscribers","subscription_url":"https://api.github.com/repos/rxin/spark/subscription","commits_url":"https://api.github.com/repos/rxin/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/rxin/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/rxin/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/rxin/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/rxin/spark/contents/{+path}","compare_url":"https://api.github.com/repos/rxin/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rxin/spark/merges","archive_url":"https://api.github.com/repos/rxin/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rxin/spark/downloads","issues_url":"https://api.github.com/repos/rxin/spark/issues{/number}","pulls_url":"https://api.github.com/repos/rxin/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/rxin/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/rxin/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rxin/spark/labels{/name}","releases_url":"https://api.github.com/repos/rxin/spark/releases{/id}","created_at":"2014-02-25T23:55:52Z","updated_at":"2015-01-23T06:12:29Z","pushed_at":"2015-06-09T06:04:38Z","git_url":"git://github.com/rxin/spark.git","ssh_url":"git@github.com:rxin/spark.git","clone_url":"https://github.com/rxin/spark.git","svn_url":"https://github.com/rxin/spark","homepage":null,"size":104554,"stargazers_count":2,"watchers_count":2,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":0,"forks":5,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"51853891686f353dc9decc31066b0de01ed8b49e","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-09T07:49:50Z","pushed_at":"2015-06-09T08:05:53Z","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":1449517,"stargazers_count":4267,"watchers_count":4267,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3744,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":336,"forks":3744,"open_issues":336,"watchers":4267,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6710"},"html":{"href":"https://github.com/apache/spark/pull/6710"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6710"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6710/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6710/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6710/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/69308222d1b65bd75c3b40b1e4da8f6161958535"}}}}