While writing a spark dataframe using write method to a csv file, the csv file is getting populated as "" for null strings
101|abc|""|555
102|""|xyz|743
Using the below code:
dataFrame
.coalesce(16)
.write
.format("csv")
.option("delimiter", "|")
.option("treatEmptyValuesAsNulls", "true")
.option("nullValue", null)
.option("emptyValue", null)
.mode(SaveMode.Overwrite)
.save(path)
Expected output:
101|abc|null|555
102|null|xyz|743
Spark version 3.2 and Scala version 2.1
null. The value fornullValueshould be a string.option("nullValue", null). So, what happens when you replace this withoption("nullValue", "null")?