Skip to content

Proposal: New option to distinguish null from empty string#15

Closed
t-suwa wants to merge 4 commits into
apache:masterfrom
t-suwa:missing-column-values-are-null
Closed

Proposal: New option to distinguish null from empty string#15
t-suwa wants to merge 4 commits into
apache:masterfrom
t-suwa:missing-column-values-are-null

Conversation

@t-suwa

@t-suwa t-suwa commented Feb 1, 2017

Copy link
Copy Markdown

It is critical to distinguish null from empty string for accomplishing data migration between different RDBMS using csv files.

Unfortunately, CSVParser does not support this functionality and returns ["", "", "", ""] as a result of parsing ",,\"\",". Thus, it impossible to make nullable columns have null instead of empty string when importing data from csv files.

So I'd like to add a new option to distinguish them.

  • CSVFormat.withMissingColumnValuesAreNull()

With this option on, you can get [null, null, "", null] as a result of above input data. Its default value is off and CSVParser keeps backward compatibility.

@coveralls

coveralls commented Feb 1, 2017

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 93.168% when pulling 9412e00 on t-suwa:missing-column-values-are-null into b1e5d93 on apache:master.

@garydgregory

Copy link
Copy Markdown
Member

What about:

Open Declaration CSVFormat org.apache.commons.csv.CSVFormat.withNullString(String nullString)

Returns a new CSVFormat with conversions to and from null for strings on input and output.
•Reading: Converts strings equal to the given nullString to null when reading records.
•Writing: Writes null as the given nullString when writing records.
Parameters:nullString the String to convert to and from null. No substitution occurs if nullReturns:A new CSVFormat that is equal to this but with the specified null conversion string.

?

@t-suwa

t-suwa commented Feb 2, 2017

Copy link
Copy Markdown
Author

Not sufficient. It does not provide a way to detect unquoted empty strings only. Take a look at the test case.

https://github.com/t-suwa/commons-csv/commit/9412e001d2e3d598edb6f51e051d2ef0116ad514

or am I missing something ?

@garydgregory

Copy link
Copy Markdown
Member

I think this is now obsolete in git master, see commit ac280e7.

DarrenJAN added a commit to DarrenJAN/commons-csv that referenced this pull request Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants