{"action":"created","comment":{"url":"https://api.github.com/repos/databricks/spark-csv/pulls/comments/39914449","id":39914449,"diff_hunk":"@@ -38,6 +38,7 @@ package object csv {\n         parserLib: String = \"COMMONS\",\n         ignoreLeadingWhiteSpace: Boolean = false,\n         ignoreTrailingWhiteSpace: Boolean = false,\n+        treatEmptyValuesAsNulls: Boolean = false,","path":"src/main/scala/com/databricks/spark/csv/package.scala","position":4,"original_position":4,"commit_id":"48d7aa61d680103a58cad5d298c60ad2274fbec1","original_commit_id":"48d7aa61d680103a58cad5d298c60ad2274fbec1","user":{"login":"falaki","id":512364,"avatar_url":"https://avatars.githubusercontent.com/u/512364?v=3","gravatar_id":"","url":"https://api.github.com/users/falaki","html_url":"https://github.com/falaki","followers_url":"https://api.github.com/users/falaki/followers","following_url":"https://api.github.com/users/falaki/following{/other_user}","gists_url":"https://api.github.com/users/falaki/gists{/gist_id}","starred_url":"https://api.github.com/users/falaki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/falaki/subscriptions","organizations_url":"https://api.github.com/users/falaki/orgs","repos_url":"https://api.github.com/users/falaki/repos","events_url":"https://api.github.com/users/falaki/events{/privacy}","received_events_url":"https://api.github.com/users/falaki/received_events","type":"User","site_admin":false},"body":"This is an auxiliary method that is just for convenience. Users are encouraged to use the builder patter. For that reason, and to keep MiMa compatibility, @andy327 please remove the new option from ```csvFile```. In future we may completely remove this method.","created_at":"2015-09-19T01:28:51Z","updated_at":"2015-09-19T01:28:51Z","html_url":"https://github.com/databricks/spark-csv/pull/147#discussion_r39914449","pull_request_url":"https://api.github.com/repos/databricks/spark-csv/pulls/147","_links":{"self":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/comments/39914449"},"html":{"href":"https://github.com/databricks/spark-csv/pull/147#discussion_r39914449"},"pull_request":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/147"}}},"pull_request":{"url":"https://api.github.com/repos/databricks/spark-csv/pulls/147","id":45065413,"html_url":"https://github.com/databricks/spark-csv/pull/147","diff_url":"https://github.com/databricks/spark-csv/pull/147.diff","patch_url":"https://github.com/databricks/spark-csv/pull/147.patch","issue_url":"https://api.github.com/repos/databricks/spark-csv/issues/147","number":147,"state":"open","locked":false,"title":"Roundtrip null values of any type","user":{"login":"andy327","id":2125475,"avatar_url":"https://avatars.githubusercontent.com/u/2125475?v=3","gravatar_id":"","url":"https://api.github.com/users/andy327","html_url":"https://github.com/andy327","followers_url":"https://api.github.com/users/andy327/followers","following_url":"https://api.github.com/users/andy327/following{/other_user}","gists_url":"https://api.github.com/users/andy327/gists{/gist_id}","starred_url":"https://api.github.com/users/andy327/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andy327/subscriptions","organizations_url":"https://api.github.com/users/andy327/orgs","repos_url":"https://api.github.com/users/andy327/repos","events_url":"https://api.github.com/users/andy327/events{/privacy}","received_events_url":"https://api.github.com/users/andy327/received_events","type":"User","site_admin":false},"body":"This pull request adds functionality to spark-csv with the goal of having the ability to write null values to file and read them back out again as null. Two changes were made to enable this.\r\n\r\nFirst, since the `com.databricks.spark.csv` package previously had the null string hardcoded to \"`null`\" when saving to a csv file, this was changed to read the null token out of the passed in parameters map, from the value for \"`nullToken`\", enabling writing null values as empty strings by use of this option. The default is left to \"`null`\" to maintain the previous behavior of the library.\r\n\r\nSecondly, the `castTo` method from `com.databricks.spark.csv.util.TypeCast` had an impossible-to-reach case statement when the `castType` was an instance of `StringType`. As a result, it was not possible to read string values from file as null. This pull request adds a setting 'treatEmptyValuesAsNulls' that allows empty string values in fields that are marked as nullable to be read as null values, as expected. Again, the previous behavior is enabled by default, so this pull request only changes the behavior when `treatEmptyValuesAsNulls` is explicitly set to true. The appropriate changes to `CsvParser` and `CsvRelation` were made to include this new setting. \r\n\r\nAdditionally, a unit test has been added to `CsvSuite` to test the ability to round-trip (both string and non-string) null values by writing nulls and reading them back out again as nulls.","created_at":"2015-09-15T15:39:32Z","updated_at":"2015-09-19T01:28:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e004a9b8a8004250a745d66a553a9c5b7eb6ba3a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/databricks/spark-csv/pulls/147/commits","review_comments_url":"https://api.github.com/repos/databricks/spark-csv/pulls/147/comments","review_comment_url":"https://api.github.com/repos/databricks/spark-csv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/databricks/spark-csv/issues/147/comments","statuses_url":"https://api.github.com/repos/databricks/spark-csv/statuses/48d7aa61d680103a58cad5d298c60ad2274fbec1","head":{"label":"tresata-opensource:feat-set-null-tokens","ref":"feat-set-null-tokens","sha":"48d7aa61d680103a58cad5d298c60ad2274fbec1","user":{"login":"tresata-opensource","id":9121872,"avatar_url":"https://avatars.githubusercontent.com/u/9121872?v=3","gravatar_id":"","url":"https://api.github.com/users/tresata-opensource","html_url":"https://github.com/tresata-opensource","followers_url":"https://api.github.com/users/tresata-opensource/followers","following_url":"https://api.github.com/users/tresata-opensource/following{/other_user}","gists_url":"https://api.github.com/users/tresata-opensource/gists{/gist_id}","starred_url":"https://api.github.com/users/tresata-opensource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tresata-opensource/subscriptions","organizations_url":"https://api.github.com/users/tresata-opensource/orgs","repos_url":"https://api.github.com/users/tresata-opensource/repos","events_url":"https://api.github.com/users/tresata-opensource/events{/privacy}","received_events_url":"https://api.github.com/users/tresata-opensource/received_events","type":"Organization","site_admin":false},"repo":{"id":42471075,"name":"spark-csv","full_name":"tresata-opensource/spark-csv","owner":{"login":"tresata-opensource","id":9121872,"avatar_url":"https://avatars.githubusercontent.com/u/9121872?v=3","gravatar_id":"","url":"https://api.github.com/users/tresata-opensource","html_url":"https://github.com/tresata-opensource","followers_url":"https://api.github.com/users/tresata-opensource/followers","following_url":"https://api.github.com/users/tresata-opensource/following{/other_user}","gists_url":"https://api.github.com/users/tresata-opensource/gists{/gist_id}","starred_url":"https://api.github.com/users/tresata-opensource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tresata-opensource/subscriptions","organizations_url":"https://api.github.com/users/tresata-opensource/orgs","repos_url":"https://api.github.com/users/tresata-opensource/repos","events_url":"https://api.github.com/users/tresata-opensource/events{/privacy}","received_events_url":"https://api.github.com/users/tresata-opensource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tresata-opensource/spark-csv","description":"CSV data source for Spark SQL and DataFrames","fork":true,"url":"https://api.github.com/repos/tresata-opensource/spark-csv","forks_url":"https://api.github.com/repos/tresata-opensource/spark-csv/forks","keys_url":"https://api.github.com/repos/tresata-opensource/spark-csv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tresata-opensource/spark-csv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tresata-opensource/spark-csv/teams","hooks_url":"https://api.github.com/repos/tresata-opensource/spark-csv/hooks","issue_events_url":"https://api.github.com/repos/tresata-opensource/spark-csv/issues/events{/number}","events_url":"https://api.github.com/repos/tresata-opensource/spark-csv/events","assignees_url":"https://api.github.com/repos/tresata-opensource/spark-csv/assignees{/user}","branches_url":"https://api.github.com/repos/tresata-opensource/spark-csv/branches{/branch}","tags_url":"https://api.github.com/repos/tresata-opensource/spark-csv/tags","blobs_url":"https://api.github.com/repos/tresata-opensource/spark-csv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tresata-opensource/spark-csv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tresata-opensource/spark-csv/git/refs{/sha}","trees_url":"https://api.github.com/repos/tresata-opensource/spark-csv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tresata-opensource/spark-csv/statuses/{sha}","languages_url":"https://api.github.com/repos/tresata-opensource/spark-csv/languages","stargazers_url":"https://api.github.com/repos/tresata-opensource/spark-csv/stargazers","contributors_url":"https://api.github.com/repos/tresata-opensource/spark-csv/contributors","subscribers_url":"https://api.github.com/repos/tresata-opensource/spark-csv/subscribers","subscription_url":"https://api.github.com/repos/tresata-opensource/spark-csv/subscription","commits_url":"https://api.github.com/repos/tresata-opensource/spark-csv/commits{/sha}","git_commits_url":"https://api.github.com/repos/tresata-opensource/spark-csv/git/commits{/sha}","comments_url":"https://api.github.com/repos/tresata-opensource/spark-csv/comments{/number}","issue_comment_url":"https://api.github.com/repos/tresata-opensource/spark-csv/issues/comments{/number}","contents_url":"https://api.github.com/repos/tresata-opensource/spark-csv/contents/{+path}","compare_url":"https://api.github.com/repos/tresata-opensource/spark-csv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tresata-opensource/spark-csv/merges","archive_url":"https://api.github.com/repos/tresata-opensource/spark-csv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tresata-opensource/spark-csv/downloads","issues_url":"https://api.github.com/repos/tresata-opensource/spark-csv/issues{/number}","pulls_url":"https://api.github.com/repos/tresata-opensource/spark-csv/pulls{/number}","milestones_url":"https://api.github.com/repos/tresata-opensource/spark-csv/milestones{/number}","notifications_url":"https://api.github.com/repos/tresata-opensource/spark-csv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tresata-opensource/spark-csv/labels{/name}","releases_url":"https://api.github.com/repos/tresata-opensource/spark-csv/releases{/id}","created_at":"2015-09-14T19:15:12Z","updated_at":"2015-09-14T19:15:12Z","pushed_at":"2015-09-17T00:22:24Z","git_url":"git://github.com/tresata-opensource/spark-csv.git","ssh_url":"git@github.com:tresata-opensource/spark-csv.git","clone_url":"https://github.com/tresata-opensource/spark-csv.git","svn_url":"https://github.com/tresata-opensource/spark-csv","homepage":"http://databricks.com/","size":359,"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":"databricks:master","ref":"master","sha":"81ed3b3c8189ab0cfd182e56f6a6dde9a34b934c","user":{"login":"databricks","id":4998052,"avatar_url":"https://avatars.githubusercontent.com/u/4998052?v=3","gravatar_id":"","url":"https://api.github.com/users/databricks","html_url":"https://github.com/databricks","followers_url":"https://api.github.com/users/databricks/followers","following_url":"https://api.github.com/users/databricks/following{/other_user}","gists_url":"https://api.github.com/users/databricks/gists{/gist_id}","starred_url":"https://api.github.com/users/databricks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/databricks/subscriptions","organizations_url":"https://api.github.com/users/databricks/orgs","repos_url":"https://api.github.com/users/databricks/repos","events_url":"https://api.github.com/users/databricks/events{/privacy}","received_events_url":"https://api.github.com/users/databricks/received_events","type":"Organization","site_admin":false},"repo":{"id":27461793,"name":"spark-csv","full_name":"databricks/spark-csv","owner":{"login":"databricks","id":4998052,"avatar_url":"https://avatars.githubusercontent.com/u/4998052?v=3","gravatar_id":"","url":"https://api.github.com/users/databricks","html_url":"https://github.com/databricks","followers_url":"https://api.github.com/users/databricks/followers","following_url":"https://api.github.com/users/databricks/following{/other_user}","gists_url":"https://api.github.com/users/databricks/gists{/gist_id}","starred_url":"https://api.github.com/users/databricks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/databricks/subscriptions","organizations_url":"https://api.github.com/users/databricks/orgs","repos_url":"https://api.github.com/users/databricks/repos","events_url":"https://api.github.com/users/databricks/events{/privacy}","received_events_url":"https://api.github.com/users/databricks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/databricks/spark-csv","description":"CSV data source for Spark SQL and DataFrames","fork":false,"url":"https://api.github.com/repos/databricks/spark-csv","forks_url":"https://api.github.com/repos/databricks/spark-csv/forks","keys_url":"https://api.github.com/repos/databricks/spark-csv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/databricks/spark-csv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/databricks/spark-csv/teams","hooks_url":"https://api.github.com/repos/databricks/spark-csv/hooks","issue_events_url":"https://api.github.com/repos/databricks/spark-csv/issues/events{/number}","events_url":"https://api.github.com/repos/databricks/spark-csv/events","assignees_url":"https://api.github.com/repos/databricks/spark-csv/assignees{/user}","branches_url":"https://api.github.com/repos/databricks/spark-csv/branches{/branch}","tags_url":"https://api.github.com/repos/databricks/spark-csv/tags","blobs_url":"https://api.github.com/repos/databricks/spark-csv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/databricks/spark-csv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/databricks/spark-csv/git/refs{/sha}","trees_url":"https://api.github.com/repos/databricks/spark-csv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/databricks/spark-csv/statuses/{sha}","languages_url":"https://api.github.com/repos/databricks/spark-csv/languages","stargazers_url":"https://api.github.com/repos/databricks/spark-csv/stargazers","contributors_url":"https://api.github.com/repos/databricks/spark-csv/contributors","subscribers_url":"https://api.github.com/repos/databricks/spark-csv/subscribers","subscription_url":"https://api.github.com/repos/databricks/spark-csv/subscription","commits_url":"https://api.github.com/repos/databricks/spark-csv/commits{/sha}","git_commits_url":"https://api.github.com/repos/databricks/spark-csv/git/commits{/sha}","comments_url":"https://api.github.com/repos/databricks/spark-csv/comments{/number}","issue_comment_url":"https://api.github.com/repos/databricks/spark-csv/issues/comments{/number}","contents_url":"https://api.github.com/repos/databricks/spark-csv/contents/{+path}","compare_url":"https://api.github.com/repos/databricks/spark-csv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/databricks/spark-csv/merges","archive_url":"https://api.github.com/repos/databricks/spark-csv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/databricks/spark-csv/downloads","issues_url":"https://api.github.com/repos/databricks/spark-csv/issues{/number}","pulls_url":"https://api.github.com/repos/databricks/spark-csv/pulls{/number}","milestones_url":"https://api.github.com/repos/databricks/spark-csv/milestones{/number}","notifications_url":"https://api.github.com/repos/databricks/spark-csv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/databricks/spark-csv/labels{/name}","releases_url":"https://api.github.com/repos/databricks/spark-csv/releases{/id}","created_at":"2014-12-03T00:56:21Z","updated_at":"2015-09-18T07:27:04Z","pushed_at":"2015-09-18T22:09:05Z","git_url":"git://github.com/databricks/spark-csv.git","ssh_url":"git@github.com:databricks/spark-csv.git","clone_url":"https://github.com/databricks/spark-csv.git","svn_url":"https://github.com/databricks/spark-csv","homepage":"http://databricks.com/","size":1073,"stargazers_count":205,"watchers_count":205,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":83,"mirror_url":null,"open_issues_count":30,"forks":83,"open_issues":30,"watchers":205,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/147"},"html":{"href":"https://github.com/databricks/spark-csv/pull/147"},"issue":{"href":"https://api.github.com/repos/databricks/spark-csv/issues/147"},"comments":{"href":"https://api.github.com/repos/databricks/spark-csv/issues/147/comments"},"review_comments":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/147/comments"},"review_comment":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/147/commits"},"statuses":{"href":"https://api.github.com/repos/databricks/spark-csv/statuses/48d7aa61d680103a58cad5d298c60ad2274fbec1"}}}}