{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/86658461","pull_request_review_id":7308880,"id":86658461,"diff_hunk":"@@ -97,17 +101,15 @@ case class Rand(seed: Long) extends RDG {\n        -0.3254147983080288\n       > SELECT _FUNC_(0);\n        1.1164209726833079\n+      > SELECT _FUNC_(null);\n+       1.1164209726833079\n   \"\"\")\n // scalastyle:on line.size.limit\n-case class Randn(seed: Long) extends RDG {\n-  override protected def evalInternal(input: InternalRow): Double = rng.nextGaussian()\n+case class Randn(child: Expression) extends RDG {\n \n-  def this() = this(Utils.random.nextLong())\n+  def this() = this(Literal(Utils.random.nextLong()))","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/randomExpressions.scala","position":93,"original_position":93,"commit_id":"160ea54c8b041904b0e98be0b56bda6529f91d93","original_commit_id":"160ea54c8b041904b0e98be0b56bda6529f91d93","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"body":"The complier seems complaining if we specify the return type in `def this`.","created_at":"2016-11-05T05:19:46Z","updated_at":"2016-11-05T05:19:46Z","html_url":"https://github.com/apache/spark/pull/15432#discussion_r86658461","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/15432","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/86658461"},"html":{"href":"https://github.com/apache/spark/pull/15432#discussion_r86658461"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/15432"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/15432","id":88799096,"html_url":"https://github.com/apache/spark/pull/15432","diff_url":"https://github.com/apache/spark/pull/15432.diff","patch_url":"https://github.com/apache/spark/pull/15432.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/15432","number":15432,"state":"open","locked":false,"title":"[SPARK-17854][SQL] rand/randn allows null/long as input seed","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\n\nThis PR proposes `rand`/`randn` accept `null` as input in Scala/SQL and `LongType` as input in SQL. In this case, it treats the values as `0`.\n\nSo, this PR includes both changes below:\n- `null` support\n  \n  It seems MySQL also accepts this.\n  \n  ``` sql\n  mysql> select rand(0);\n  +---------------------+\n  | rand(0)             |\n  +---------------------+\n  | 0.15522042769493574 |\n  +---------------------+\n  1 row in set (0.00 sec)\n  \n  mysql> select rand(NULL);\n  +---------------------+\n  | rand(NULL)          |\n  +---------------------+\n  | 0.15522042769493574 |\n  +---------------------+\n  1 row in set (0.00 sec)\n  ```\n  \n  and also Hive does according to [HIVE-14694](https://issues.apache.org/jira/browse/HIVE-14694)\n  \n  So the codes below:\n  \n  ``` scala\n  spark.range(1).selectExpr(\"rand(null)\").show()\n  ```\n  \n  prints..\n  \n  **Before**\n  \n  ```\n    Input argument to rand must be an integer literal.;; line 1 pos 0\n  org.apache.spark.sql.AnalysisException: Input argument to rand must be an integer literal.;; line 1 pos 0\n  at org.apache.spark.sql.catalyst.analysis.FunctionRegistry$$anonfun$5.apply(FunctionRegistry.scala:465)\n  at org.apache.spark.sql.catalyst.analysis.FunctionRegistry$$anonfun$5.apply(FunctionRegistry.scala:444)\n  ```\n  \n  **After**\n  \n  ```\n    +-----------------------+\n    |rand(CAST(NULL AS INT))|\n    +-----------------------+\n    |    0.13385709732307427|\n    +-----------------------+\n  ```\n- `LongType` support in SQL.\n  \n  In addition, it make the function allows to take `LongType` consistently within Scala/SQL.\n  \n  In more details, the codes below:\n  \n  ``` scala\n  spark.range(1).select(rand(1), rand(1L)).show()\n  spark.range(1).selectExpr(\"rand(1)\", \"rand(1L)\").show()\n  ```\n  \n  prints..\n  \n  **Before**\n  \n  ```\n  +------------------+------------------+\n  |           rand(1)|           rand(1)|\n  +------------------+------------------+\n  |0.2630967864682161|0.2630967864682161|\n  +------------------+------------------+\n  \n  \n  Input argument to rand must be an integer literal.;; line 1 pos 0\n  org.apache.spark.sql.AnalysisException: Input argument to rand must be an integer literal.;; line 1 pos 0\n  at org.apache.spark.sql.catalyst.analysis.FunctionRegistry$$anonfun$5.apply(FunctionRegistry.scala:465)\n  at\n  ```\n  \n  **After**\n  \n  ```\n  +------------------+------------------+\n  |           rand(1)|           rand(1)|\n  +------------------+------------------+\n  |0.2630967864682161|0.2630967864682161|\n  +------------------+------------------+\n  \n  +------------------+------------------+\n  |           rand(1)|           rand(1)|\n  +------------------+------------------+\n  |0.2630967864682161|0.2630967864682161|\n  +------------------+------------------+\n  ```\n## How was this patch tested?\n\nUnit tests in `DataFrameSuite.scala` and `RandomSuite.scala`.\n","created_at":"2016-10-11T09:29:02Z","updated_at":"2016-11-05T05:19:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94c5598187386960304bc5a960ad726082325e60","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/15432/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/15432/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/15432/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/160ea54c8b041904b0e98be0b56bda6529f91d93","head":{"label":"HyukjinKwon:SPARK-17854","ref":"SPARK-17854","sha":"160ea54c8b041904b0e98be0b56bda6529f91d93","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"repo":{"id":42300713,"name":"spark","full_name":"HyukjinKwon/spark","owner":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HyukjinKwon/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/HyukjinKwon/spark","forks_url":"https://api.github.com/repos/HyukjinKwon/spark/forks","keys_url":"https://api.github.com/repos/HyukjinKwon/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HyukjinKwon/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HyukjinKwon/spark/teams","hooks_url":"https://api.github.com/repos/HyukjinKwon/spark/hooks","issue_events_url":"https://api.github.com/repos/HyukjinKwon/spark/issues/events{/number}","events_url":"https://api.github.com/repos/HyukjinKwon/spark/events","assignees_url":"https://api.github.com/repos/HyukjinKwon/spark/assignees{/user}","branches_url":"https://api.github.com/repos/HyukjinKwon/spark/branches{/branch}","tags_url":"https://api.github.com/repos/HyukjinKwon/spark/tags","blobs_url":"https://api.github.com/repos/HyukjinKwon/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HyukjinKwon/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HyukjinKwon/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/HyukjinKwon/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HyukjinKwon/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/HyukjinKwon/spark/languages","stargazers_url":"https://api.github.com/repos/HyukjinKwon/spark/stargazers","contributors_url":"https://api.github.com/repos/HyukjinKwon/spark/contributors","subscribers_url":"https://api.github.com/repos/HyukjinKwon/spark/subscribers","subscription_url":"https://api.github.com/repos/HyukjinKwon/spark/subscription","commits_url":"https://api.github.com/repos/HyukjinKwon/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/HyukjinKwon/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/HyukjinKwon/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/HyukjinKwon/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/HyukjinKwon/spark/contents/{+path}","compare_url":"https://api.github.com/repos/HyukjinKwon/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HyukjinKwon/spark/merges","archive_url":"https://api.github.com/repos/HyukjinKwon/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HyukjinKwon/spark/downloads","issues_url":"https://api.github.com/repos/HyukjinKwon/spark/issues{/number}","pulls_url":"https://api.github.com/repos/HyukjinKwon/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/HyukjinKwon/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/HyukjinKwon/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HyukjinKwon/spark/labels{/name}","releases_url":"https://api.github.com/repos/HyukjinKwon/spark/releases{/id}","deployments_url":"https://api.github.com/repos/HyukjinKwon/spark/deployments","created_at":"2015-09-11T09:47:43Z","updated_at":"2016-04-11T01:30:54Z","pushed_at":"2016-11-05T05:12:03Z","git_url":"git://github.com/HyukjinKwon/spark.git","ssh_url":"git@github.com:HyukjinKwon/spark.git","clone_url":"https://github.com/HyukjinKwon/spark.git","svn_url":"https://github.com/HyukjinKwon/spark","homepage":null,"size":249059,"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":"a08463b1d32348a81d0f148dfaf22741d5c23b1a","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}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-11-05T02:53:31Z","pushed_at":"2016-11-05T05:12:05Z","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":606961,"stargazers_count":10618,"watchers_count":10618,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9907,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":463,"forks":9907,"open_issues":463,"watchers":10618,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/15432"},"html":{"href":"https://github.com/apache/spark/pull/15432"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/15432"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/15432/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/15432/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/15432/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/160ea54c8b041904b0e98be0b56bda6529f91d93"}}}}
{"actor":{"display_login":"HyukjinKwon"}}