4

I have a CSV to write that has that schema :

StructType s = schema.add("codeCommuneCR", StringType, false);
s = s.add("nomCommuneCR", StringType, false);
s = s.add("populationCR", IntegerType, false);
s = s.add("resultatComptable", IntegerType, false);

If I don't provide an option "quoteMode" or even if I set it to NON_NUMERIC, this way :

ds.coalesce(1).write().mode(SaveMode.Overwrite)
.option("header", "true")
.option("quoteMode", "NON_NUMERIC")
.option("quote", "\"")
.csv("./target/out_200071470.csv");

the CSV written by Spark is this one :

codeCommuneCR,nomCommuneCR,populationCR,resultatComptable
03142,LENAX,267,43

If I set an option "quoteAll" instead, like that :

ds.coalesce(1).write().mode(SaveMode.Overwrite)
.option("header", "true")
.option("quoteAll", true)
.option("quote", "\"")
.csv("./target/out_200071470.csv");

it generates :

codeCommuneCR,nomCommuneCR,populationCR,resultatComptable
"03142","LENAX","267","43"

But I would like .option("quoteMode", "NON_NUMERIC") to generate :

codeCommuneCR,nomCommuneCR,populationCR,resultatComptable
"03142","LENAX",267,43

according to my schema.

How should my settings be done ?

Regards,

1
  • Could be a bug. Consider filing a report at issues.apache.org Commented Feb 17, 2019 at 7:14

1 Answer 1

1

I've opened an issue about it, and learnt that Spark handles now the CSV through Univocity, who do not support anymore this feature.

Re-adding it is not planned, the "quoteMode" option is no more taken into account.

Sign up to request clarification or add additional context in comments.

2 Comments

How come it's unplanned? I can't find any other way to differentiate between empty strings and nulls in CSV with Spark.
The emptyValue and the nullValue options of the DataFrameWriter should help differentiate between empty strings and nulls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.