Uh oh!
There was an error while loading. Please reload this page.
[SPARK-25241][SQL] Configurable empty values when reading/writing CSV files - #22234
[SPARK-25241][SQL] Configurable empty values when reading/writing CSV files#22234mmolimar wants to merge 6 commits into
Conversation
Should the new option be taken into account there: and here: ? |
| maxCharsPerColumn=None, maxMalformedLogPerPartition=None, mode=None, | ||
| columnNameOfCorruptRecord=None, multiLine=None, charToEscapeQuoteEscaping=None, | ||
| samplingRatio=None, enforceSchema=None): | ||
| ignoreTrailingWhiteSpace=None, nullValue=None, emptyValue=None, nanValue=None, |
There was a problem hiding this comment.
It should be put at the last; otherwise, it's going to break existing Python app when the arguments are given positionally.
There was a problem hiding this comment.
We should add new parameter at the end. +1
HyukjinKwon
commented
Aug 26, 2018
ok to test |
MaxGekk
left a comment
There was a problem hiding this comment.
In light of discussion in the ticket https://issues.apache.org/jira/browse/SPARK-17916, could you write a test and check the case when empty values are written without quotes as it was in Spark 2.3 by default.
SparkQA
commented
Aug 26, 2018
Test build #95259 has finished for PR 22234 at commit
|
mmolimar
commented
Aug 26, 2018
@MaxGekk I added what you suggested as well. |
| nanValue=nanValue, positiveInf=positiveInf, negativeInf=negativeInf, | ||
| dateFormat=dateFormat, timestampFormat=timestampFormat, maxColumns=maxColumns, | ||
| maxCharsPerColumn=maxCharsPerColumn, | ||
| emptyValue=emptyValue, nanValue=nanValue, positiveInf=positiveInf, |
There was a problem hiding this comment.
I would put this at the end as well for readability.
| val nullValue = parameters.getOrElse("nullValue", "") | ||
| val emptyValueInRead = parameters.getOrElse("emptyValue", "") |
There was a problem hiding this comment.
I would just call it emptyValue for consistency with other options here.
There was a problem hiding this comment.
I though that as well. Just for the shake of providing backwards compatibility as we already have in ignoreLeadingWhiteSpaceInRead and ignoreLeadingWhiteSpaceFlagInWrite I implemented that in that way.
What do you say?
There was a problem hiding this comment.
I had to name them differently names because the default values are different. Ah, yea then it makes sense here. I rushed to read.
SparkQA
commented
Aug 27, 2018
Test build #95270 has finished for PR 22234 at commit
|
SparkQA
commented
Aug 27, 2018
Test build #95271 has finished for PR 22234 at commit
|
SparkQA
commented
Aug 27, 2018
Test build #95274 has finished for PR 22234 at commit
|
HyukjinKwon
commented
Aug 27, 2018
Seems okay but I or someone else should take a closer look before getting this in. |
| def inferField(typeSoFar: DataType, field: String, options: CSVOptions): DataType = { | ||
| if (field == null || field.isEmpty || field == options.nullValue) { | ||
| if (field == null || field.isEmpty || field == options.nullValue || | ||
| field == options.emptyValueInRead) { |
There was a problem hiding this comment.
I wouldn't do this for now. It needs another review iteration. Let's revert this back.
| // When there are empty strings or the values set in `nullValue`, put the | ||
| // index as the suffix. | ||
| if (value == null || value.isEmpty || value == options.nullValue || | ||
| value == options.emptyValueInRead) { |
There was a problem hiding this comment.
Do I revert these both changes @HyukjinKwon then?
HyukjinKwon
left a comment
There was a problem hiding this comment.
Looks good. Let me take another look before getting this in.
gatorsmile
commented
Sep 4, 2018
Did we introduce any behavior change in #21273? Does this PR resolve it? |
HyukjinKwon
commented
Sep 5, 2018
From my understanding, yea. The problem here is sounds like ambiguity in empty strings since they can be interpreted as empty strings and also This PR proposes an ability explicitly set the empty value to work around the behaviour change. |
gatorsmile
commented
Sep 5, 2018
Have we documented the behavior changes in the migration guide? If not, can we do it? |
HyukjinKwon
commented
Sep 5, 2018
This is rather a quite corner case (see the elaborated cases in the JIRA SPARK-17916) and there's ambiguity to treat this as a bug or a proper behaviour change; however, I don't object if this can be worth enough as something that should be mentioned. cc @MaxGekk for a followup |
MaxGekk
commented
Sep 7, 2018
@HyukjinKwon Do you mean to update migration guide in master and probably in Spark 2.4? I don't think this should be considered as a bug because current version and previous versions of Spark can read saved CSV files correctly. Yes, for now empty strings are saved as |
HyukjinKwon
commented
Sep 7, 2018
Oh no I mean we fixed a bug.. |
gatorsmile
commented
Sep 8, 2018
@MaxGekk Could you take this PR over? I think we need to merge this to Spark 2.4. Users can set the behaviors to the previous one by this new conf |
MaxGekk
commented
Sep 8, 2018
@gatorsmile@HyukjinKwon Please, take a look at #22367 |
HyukjinKwon
commented
Sep 11, 2018
…sed as null when nullValue is set. ## What changes were proposed in this pull request? In the PR, I propose new CSV option `emptyValue` and an update in the SQL Migration Guide which describes how to revert previous behavior when empty strings were not written at all. Since Spark 2.4, empty strings are saved as `""` to distinguish them from saved `null`s. Closes#22234Closes#22367 ## How was this patch tested? It was tested by `CSVSuite` and new tests added in the PR #22234Closes#22389 from MaxGekk/csv-empty-value-master. Lead-authored-by: Mario Molina <mmolimar@gmail.com> Co-authored-by: Maxim Gekk <maxim.gekk@databricks.com> Signed-off-by: hyukjinkwon <gurwls223@apache.org> (cherry picked from commit c9cb393) Signed-off-by: hyukjinkwon <gurwls223@apache.org>
…sed as null when nullValue is set. ## What changes were proposed in this pull request? In the PR, I propose new CSV option `emptyValue` and an update in the SQL Migration Guide which describes how to revert previous behavior when empty strings were not written at all. Since Spark 2.4, empty strings are saved as `""` to distinguish them from saved `null`s. Closesapache#22234Closesapache#22367 ## How was this patch tested? It was tested by `CSVSuite` and new tests added in the PR apache#22234Closesapache#22389 from MaxGekk/csv-empty-value-master. Lead-authored-by: Mario Molina <mmolimar@gmail.com> Co-authored-by: Maxim Gekk <maxim.gekk@databricks.com> Signed-off-by: hyukjinkwon <gurwls223@apache.org>
What changes were proposed in this pull request?
There is an option in the CSV parser to set values when we have empty values in the CSV files or in our dataframes.
Currently, this option cannot be configured and always sets a default value (empty string for reading and
""for writing).This PR is about enabling a new CSV option in the reader/writer to set custom empty values when reading/writing CSV files.
How was this patch tested?
The changes were tested by CSVSuite adding two unit tests.