I'm trying to fill an empty value as null when I split a column in Spark. Example:
| A |
| 1.2.3 |
| 4..5 |
I was looking for:
A | A split 1 | A split 2 | A split 3 |
---|---|---|---|
1.2.3 | 1 | 2 | 3 |
4..5 | 4 | null | 5 |
I got:
A | A split 1 | A split 2 | A split 3 |
---|---|---|---|
1.2.3 | 1 | 2 | 3 |
4..5 | 4 | 5 |
My code is:
df.withColumn("A", when(split(col("A"), "\\.") =!= lit(""), split(col("A"), "\\."))
However, I got an error because due to a type mismatch:
array(string) is not a string.
It could be possible to find a solution without using a UDF?
Many thanks