I've Spark DataFrame with a Array column (StringType)
Sample DataFrame:
df = spark.createDataFrame([
[None],
[[]],
[['foo']]
]).toDF("a")
Current Output:
+-----+
| a|
+-----+
| null|
| []|
|[foo]|
+-----+
Desired Output:
+-----+
| a|
+-----+
| []|
| []|
|[foo]|
+-----+
I need to convert the Null values to an empty Array to concat with another array column.
Already tried this, but it's not working
df.withColumn("a",F.coalesce(F.col("a"),F.from_json(F.lit("[]"), T.ArrayType(T.StringType()))))