โ04-18-2024 02:22 AM - edited โ04-18-2024 02:25 AM
Hi,
I am trying to read one file which having some blank value in column and we know spark convert blank value to null value during reading, how to read blank/empty value as empty value ?? tried DBR 13.2,14.3
I have tried all possible way but its not working
โ04-18-2024 03:06 AM
May I ask why you do not want null? It is THE way to indicate a value is missing (and gives you filtering possibilities using isNull/isNotNull).
โ04-18-2024 03:48 AM
Hi @-werners- , User wants data in landing table like this only, they have some data like None as well... And can have some case when statement based on blank value and null value in next layer
โ04-18-2024 03:51 AM
.option("nullValue", "") should do the trick.
โ04-18-2024 07:16 AM
.option(nullValue, "")
empty strings are interpreted as null values by default. If you set nullValue to anything but "", like "null" or "none", empty strings will be read as empty strings and not as null values anymore.
Please check-
dataframe - Read spark csv with empty values without converting to null - Stack Overflow
โ04-18-2024 07:32 AM - edited โ04-18-2024 07:34 AM
dont quote something from stackoverflow because those are old version in spark tried.. have you tried the thing on your own to verify if this really working or not in spark3??
โ04-18-2024 08:40 AM
afaik nullValue, "" should do the trick. But I tested myself on your example and indeed it does not work.
Gonna do some checking...
โ04-24-2024 12:43 AM
OK, after some tests:
The trick is in surrounding text in your csv with quotes. Like that spark can actually make a difference between a missing value and an empty value. Missing values are null and can only be converted to something else implicitely (by using coalesce f.e.).
When a column contains '', nullvalue = "''" will create an empty value and not null.
The same for emptyValue if you want.
Not sure if it is workable for you though.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group