{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/175262443","pull_request_review_id":104770788,"id":175262443,"diff_hunk":"@@ -2063,4 +2063,178 @@ class JsonSuite extends QueryTest with SharedSQLContext with TestJsonData {\n       )\n     }\n   }\n+\n+  def testFile(fileName: String): String = {\n+    Thread.currentThread().getContextClassLoader.getResource(fileName).toString\n+  }\n+\n+  test(\"json in UTF-16 with BOM\") {\n+    val fileName = \"json-tests/utf16WithBOM.json\"\n+    val schema = new StructType().add(\"firstName\", StringType).add(\"lastName\", StringType)\n+    val jsonDF = spark.read.schema(schema)\n+      // The mode filters null rows produced because new line delimiter\n+      // for UTF-8 is used by default.","path":"sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala","position":14,"original_position":14,"commit_id":"961b48225b450f9053681405f594911896e3a7ff","original_commit_id":"961b48225b450f9053681405f594911896e3a7ff","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars0.githubusercontent.com/u/6477701?v=4","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":"This is funny that we have a test for this.","created_at":"2018-03-17T16:16:46Z","updated_at":"2018-03-17T16:16:46Z","html_url":"https://github.com/apache/spark/pull/20849#discussion_r175262443","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/20849","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/175262443"},"html":{"href":"https://github.com/apache/spark/pull/20849#discussion_r175262443"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/20849"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/20849","id":175700771,"html_url":"https://github.com/apache/spark/pull/20849","diff_url":"https://github.com/apache/spark/pull/20849.diff","patch_url":"https://github.com/apache/spark/pull/20849.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/20849","number":20849,"state":"open","locked":false,"title":"[SPARK-23723] New charset option for json datasource","user":{"login":"MaxGekk","id":1580697,"avatar_url":"https://avatars1.githubusercontent.com/u/1580697?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGekk","html_url":"https://github.com/MaxGekk","followers_url":"https://api.github.com/users/MaxGekk/followers","following_url":"https://api.github.com/users/MaxGekk/following{/other_user}","gists_url":"https://api.github.com/users/MaxGekk/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGekk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGekk/subscriptions","organizations_url":"https://api.github.com/users/MaxGekk/orgs","repos_url":"https://api.github.com/users/MaxGekk/repos","events_url":"https://api.github.com/users/MaxGekk/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGekk/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nI propose new option for JSON datasource which allows to specify charset of input and output files. Here is an example of using of the option:\r\n\r\n```\r\nspark.read.schema(schema)\r\n  .option(\"multiline\", \"true\")\r\n  .option(\"charset\", \"UTF-16LE\")\r\n  .json(fileName)\r\n```\r\n\r\nIf the option is not specified, charset auto-detection mechanism is used by default.\r\n\r\nThe option can be used for saving datasets to jsons. Currently Spark is able to save datasets into json files in UTF-8 charset only. The changes allow to save data in any supported charset. Here is the approximate list of supported charsets by Oracle Java SE: https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html . An user can specify the charset of output jsons via the charset option like .option(\"charset\", \"UTF-16\"). By default the output charset is still UTF-8 to keep backward compatibility.\r\n\r\n## How was this patch tested?\r\n\r\nI added the following tests:\r\n- reads an json file in UTF-16 charset with BOM\r\n- read json file by using charset auto detection (UTF-32BE with BOM) \r\n- read json file using of user's charset (UTF-16LE)\r\n- saving in UTF-32BE and read the result by standard library (not by Spark)\r\n- checking that default charset is UTF-8\r\n- handling wrong (unsupported) charset","created_at":"2018-03-17T13:33:50Z","updated_at":"2018-03-17T16:16:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82a7565b0e1f50d5b35caf92cdfc6e4d50f4499f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/20849/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/20849/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/20849/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/961b48225b450f9053681405f594911896e3a7ff","head":{"label":"MaxGekk:json-charset","ref":"json-charset","sha":"961b48225b450f9053681405f594911896e3a7ff","user":{"login":"MaxGekk","id":1580697,"avatar_url":"https://avatars1.githubusercontent.com/u/1580697?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGekk","html_url":"https://github.com/MaxGekk","followers_url":"https://api.github.com/users/MaxGekk/followers","following_url":"https://api.github.com/users/MaxGekk/following{/other_user}","gists_url":"https://api.github.com/users/MaxGekk/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGekk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGekk/subscriptions","organizations_url":"https://api.github.com/users/MaxGekk/orgs","repos_url":"https://api.github.com/users/MaxGekk/repos","events_url":"https://api.github.com/users/MaxGekk/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGekk/received_events","type":"User","site_admin":false},"repo":{"id":123690489,"name":"spark-1","full_name":"MaxGekk/spark-1","owner":{"login":"MaxGekk","id":1580697,"avatar_url":"https://avatars1.githubusercontent.com/u/1580697?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGekk","html_url":"https://github.com/MaxGekk","followers_url":"https://api.github.com/users/MaxGekk/followers","following_url":"https://api.github.com/users/MaxGekk/following{/other_user}","gists_url":"https://api.github.com/users/MaxGekk/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGekk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGekk/subscriptions","organizations_url":"https://api.github.com/users/MaxGekk/orgs","repos_url":"https://api.github.com/users/MaxGekk/repos","events_url":"https://api.github.com/users/MaxGekk/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGekk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MaxGekk/spark-1","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/MaxGekk/spark-1","forks_url":"https://api.github.com/repos/MaxGekk/spark-1/forks","keys_url":"https://api.github.com/repos/MaxGekk/spark-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MaxGekk/spark-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MaxGekk/spark-1/teams","hooks_url":"https://api.github.com/repos/MaxGekk/spark-1/hooks","issue_events_url":"https://api.github.com/repos/MaxGekk/spark-1/issues/events{/number}","events_url":"https://api.github.com/repos/MaxGekk/spark-1/events","assignees_url":"https://api.github.com/repos/MaxGekk/spark-1/assignees{/user}","branches_url":"https://api.github.com/repos/MaxGekk/spark-1/branches{/branch}","tags_url":"https://api.github.com/repos/MaxGekk/spark-1/tags","blobs_url":"https://api.github.com/repos/MaxGekk/spark-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MaxGekk/spark-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MaxGekk/spark-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/MaxGekk/spark-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MaxGekk/spark-1/statuses/{sha}","languages_url":"https://api.github.com/repos/MaxGekk/spark-1/languages","stargazers_url":"https://api.github.com/repos/MaxGekk/spark-1/stargazers","contributors_url":"https://api.github.com/repos/MaxGekk/spark-1/contributors","subscribers_url":"https://api.github.com/repos/MaxGekk/spark-1/subscribers","subscription_url":"https://api.github.com/repos/MaxGekk/spark-1/subscription","commits_url":"https://api.github.com/repos/MaxGekk/spark-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/MaxGekk/spark-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/MaxGekk/spark-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/MaxGekk/spark-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/MaxGekk/spark-1/contents/{+path}","compare_url":"https://api.github.com/repos/MaxGekk/spark-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MaxGekk/spark-1/merges","archive_url":"https://api.github.com/repos/MaxGekk/spark-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MaxGekk/spark-1/downloads","issues_url":"https://api.github.com/repos/MaxGekk/spark-1/issues{/number}","pulls_url":"https://api.github.com/repos/MaxGekk/spark-1/pulls{/number}","milestones_url":"https://api.github.com/repos/MaxGekk/spark-1/milestones{/number}","notifications_url":"https://api.github.com/repos/MaxGekk/spark-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MaxGekk/spark-1/labels{/name}","releases_url":"https://api.github.com/repos/MaxGekk/spark-1/releases{/id}","deployments_url":"https://api.github.com/repos/MaxGekk/spark-1/deployments","created_at":"2018-03-03T12:37:00Z","updated_at":"2018-03-17T10:19:04Z","pushed_at":"2018-03-17T12:48:14Z","git_url":"git://github.com/MaxGekk/spark-1.git","ssh_url":"git@github.com:MaxGekk/spark-1.git","clone_url":"https://github.com/MaxGekk/spark-1.git","svn_url":"https://github.com/MaxGekk/spark-1","homepage":null,"size":269483,"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,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"8a1efe3076f29259151f1fba2ff894487efb6c4e","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":"2018-03-17T12:31:37Z","pushed_at":"2018-03-17T13:33:50Z","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":269557,"stargazers_count":16528,"watchers_count":16528,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":15222,"mirror_url":null,"archived":false,"open_issues_count":479,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":15222,"open_issues":479,"watchers":16528,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/20849"},"html":{"href":"https://github.com/apache/spark/pull/20849"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/20849"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/20849/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/20849/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/20849/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/961b48225b450f9053681405f594911896e3a7ff"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"HyukjinKwon"}}