{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/138232491","pull_request_review_id":61999820,"id":138232491,"diff_hunk":"@@ -193,14 +223,35 @@ private[sql] class JacksonGenerator(\n    *\n    * @param row The row to convert\n    */\n-  def write(row: InternalRow): Unit = writeObject(writeFields(row, schema, rootFieldWriters))\n+  def write(row: InternalRow): Unit = {\n+    writeObject(writeFields(\n+      fieldWriters = rootFieldWriters,\n+      row = row,\n+      schema = dataType.asInstanceOf[StructType]))\n+  }\n+\n+\n+  /**\n+   * Transforms multiple `InternalRow`s or `MapData`s to JSON array using Jackson\n+   *\n+   * @param array The array of rows or maps to convert\n+   */\n+  def write(array: ArrayData): Unit = writeArray(writeArrayData(\n+    fieldWriter = arrElementWriter,\n+    array = array\n+  ))\n \n   /**\n-   * Transforms multiple `InternalRow`s to JSON array using Jackson\n+   * Transforms a single `MapData` to JSON object using Jackson\n    *\n-   * @param array The array of rows to convert\n+   * @param map a map to convert\n    */\n-  def write(array: ArrayData): Unit = writeArray(writeArrayData(array, arrElementWriter))\n+  def write(map: MapData): Unit = {\n+    writeObject(writeMapData(\n+      fieldWriter = mapElementWriter,","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonGenerator.scala","position":88,"original_position":88,"commit_id":"0f2dd186b48b2b46ed1367ebae811b5767ef8598","original_commit_id":"0f2dd186b48b2b46ed1367ebae811b5767ef8598","user":{"login":"viirya","id":68855,"avatar_url":"https://avatars1.githubusercontent.com/u/68855?v=4","gravatar_id":"","url":"https://api.github.com/users/viirya","html_url":"https://github.com/viirya","followers_url":"https://api.github.com/users/viirya/followers","following_url":"https://api.github.com/users/viirya/following{/other_user}","gists_url":"https://api.github.com/users/viirya/gists{/gist_id}","starred_url":"https://api.github.com/users/viirya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/viirya/subscriptions","organizations_url":"https://api.github.com/users/viirya/orgs","repos_url":"https://api.github.com/users/viirya/repos","events_url":"https://api.github.com/users/viirya/events{/privacy}","received_events_url":"https://api.github.com/users/viirya/received_events","type":"User","site_admin":false},"body":"And also add a similar comment in `write(row: InternalRow)`.","created_at":"2017-09-12T01:25:10Z","updated_at":"2017-09-12T01:25:10Z","html_url":"https://github.com/apache/spark/pull/18875#discussion_r138232491","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/18875","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/138232491"},"html":{"href":"https://github.com/apache/spark/pull/18875#discussion_r138232491"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/18875"}},"in_reply_to_id":138228185},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/18875","id":134503179,"html_url":"https://github.com/apache/spark/pull/18875","diff_url":"https://github.com/apache/spark/pull/18875.diff","patch_url":"https://github.com/apache/spark/pull/18875.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/18875","number":18875,"state":"open","locked":false,"title":"[SPARK-21513][SQL] Allow UDF to_json support converting MapType to json","user":{"login":"goldmedal","id":6974913,"avatar_url":"https://avatars3.githubusercontent.com/u/6974913?v=4","gravatar_id":"","url":"https://api.github.com/users/goldmedal","html_url":"https://github.com/goldmedal","followers_url":"https://api.github.com/users/goldmedal/followers","following_url":"https://api.github.com/users/goldmedal/following{/other_user}","gists_url":"https://api.github.com/users/goldmedal/gists{/gist_id}","starred_url":"https://api.github.com/users/goldmedal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldmedal/subscriptions","organizations_url":"https://api.github.com/users/goldmedal/orgs","repos_url":"https://api.github.com/users/goldmedal/repos","events_url":"https://api.github.com/users/goldmedal/events{/privacy}","received_events_url":"https://api.github.com/users/goldmedal/received_events","type":"User","site_admin":false},"body":"# What changes were proposed in this pull request?\r\nUDF to_json only supports converting `StructType` or `ArrayType` of `StructType`s to a json output string now. \r\nAccording to the discussion of JIRA SPARK-21513, I allow to `to_json` support converting `MapType` and `ArrayType` of `MapType`s to a json output string.\r\nThis PR is for SQL and Scala API only.\r\n\r\n# How was this patch tested?\r\nAdding unit test case.\r\n\r\ncc @viirya @HyukjinKwon ","created_at":"2017-08-07T18:53:54Z","updated_at":"2017-09-12T01:25:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"39a98c81c9fde55abde88a42eec6647d0a4fda43","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/18875/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/18875/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/18875/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/0f2dd186b48b2b46ed1367ebae811b5767ef8598","head":{"label":"goldmedal:SPARK-21513","ref":"SPARK-21513","sha":"0f2dd186b48b2b46ed1367ebae811b5767ef8598","user":{"login":"goldmedal","id":6974913,"avatar_url":"https://avatars3.githubusercontent.com/u/6974913?v=4","gravatar_id":"","url":"https://api.github.com/users/goldmedal","html_url":"https://github.com/goldmedal","followers_url":"https://api.github.com/users/goldmedal/followers","following_url":"https://api.github.com/users/goldmedal/following{/other_user}","gists_url":"https://api.github.com/users/goldmedal/gists{/gist_id}","starred_url":"https://api.github.com/users/goldmedal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldmedal/subscriptions","organizations_url":"https://api.github.com/users/goldmedal/orgs","repos_url":"https://api.github.com/users/goldmedal/repos","events_url":"https://api.github.com/users/goldmedal/events{/privacy}","received_events_url":"https://api.github.com/users/goldmedal/received_events","type":"User","site_admin":false},"repo":{"id":98996363,"name":"spark","full_name":"goldmedal/spark","owner":{"login":"goldmedal","id":6974913,"avatar_url":"https://avatars3.githubusercontent.com/u/6974913?v=4","gravatar_id":"","url":"https://api.github.com/users/goldmedal","html_url":"https://github.com/goldmedal","followers_url":"https://api.github.com/users/goldmedal/followers","following_url":"https://api.github.com/users/goldmedal/following{/other_user}","gists_url":"https://api.github.com/users/goldmedal/gists{/gist_id}","starred_url":"https://api.github.com/users/goldmedal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldmedal/subscriptions","organizations_url":"https://api.github.com/users/goldmedal/orgs","repos_url":"https://api.github.com/users/goldmedal/repos","events_url":"https://api.github.com/users/goldmedal/events{/privacy}","received_events_url":"https://api.github.com/users/goldmedal/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/goldmedal/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/goldmedal/spark","forks_url":"https://api.github.com/repos/goldmedal/spark/forks","keys_url":"https://api.github.com/repos/goldmedal/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/goldmedal/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/goldmedal/spark/teams","hooks_url":"https://api.github.com/repos/goldmedal/spark/hooks","issue_events_url":"https://api.github.com/repos/goldmedal/spark/issues/events{/number}","events_url":"https://api.github.com/repos/goldmedal/spark/events","assignees_url":"https://api.github.com/repos/goldmedal/spark/assignees{/user}","branches_url":"https://api.github.com/repos/goldmedal/spark/branches{/branch}","tags_url":"https://api.github.com/repos/goldmedal/spark/tags","blobs_url":"https://api.github.com/repos/goldmedal/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/goldmedal/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/goldmedal/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/goldmedal/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/goldmedal/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/goldmedal/spark/languages","stargazers_url":"https://api.github.com/repos/goldmedal/spark/stargazers","contributors_url":"https://api.github.com/repos/goldmedal/spark/contributors","subscribers_url":"https://api.github.com/repos/goldmedal/spark/subscribers","subscription_url":"https://api.github.com/repos/goldmedal/spark/subscription","commits_url":"https://api.github.com/repos/goldmedal/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/goldmedal/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/goldmedal/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/goldmedal/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/goldmedal/spark/contents/{+path}","compare_url":"https://api.github.com/repos/goldmedal/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/goldmedal/spark/merges","archive_url":"https://api.github.com/repos/goldmedal/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/goldmedal/spark/downloads","issues_url":"https://api.github.com/repos/goldmedal/spark/issues{/number}","pulls_url":"https://api.github.com/repos/goldmedal/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/goldmedal/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/goldmedal/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/goldmedal/spark/labels{/name}","releases_url":"https://api.github.com/repos/goldmedal/spark/releases{/id}","deployments_url":"https://api.github.com/repos/goldmedal/spark/deployments","created_at":"2017-08-01T11:59:43Z","updated_at":"2017-08-01T12:00:13Z","pushed_at":"2017-09-11T15:46:18Z","git_url":"git://github.com/goldmedal/spark.git","ssh_url":"git@github.com:goldmedal/spark.git","clone_url":"https://github.com/goldmedal/spark.git","svn_url":"https://github.com/goldmedal/spark","homepage":null,"size":262003,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"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":"6b45d7e941eba8a36be26116787322d9e3ae25d0","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","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://avatars0.githubusercontent.com/u/47359?v=4","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":"2017-09-11T18:38:03Z","pushed_at":"2017-09-12T01:06:24Z","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":262166,"stargazers_count":14274,"watchers_count":14274,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13364,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":393,"forks":13364,"open_issues":393,"watchers":14274,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/18875"},"html":{"href":"https://github.com/apache/spark/pull/18875"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/18875"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/18875/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/18875/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/18875/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/0f2dd186b48b2b46ed1367ebae811b5767ef8598"}},"author_association":"NONE"}}
{"actor":{"display_login":"viirya"}}