I got a dataframe with (String, List[String]). I want to split de List[String] and put each value from the list in a field. For example:
String 1, [1, 2, 3, 4] => String 1, 1, 2, 3, 4
Input (String, List[String]):
Hey, [wooa, mmmm, ehhh]
Hey1, [woooe, rrrr, ough, shhhhh]
Output (String, String, String, String,..., String)
Hey, wooa, mmmm, ehhh
Hey1, woooe, rrrr, ough, shhhhh
I am trying with the next code
df.withColumn("temp",split(col("fieldList"), ","))
.select(col("*") +: (0 until 9).map(i => col("temp").getItem(i).as(s"col$i")):_*)
My problem is when I execute that, I get an error like:
User class threw exception: org.apache.spark.sql.AnalysisException: cannot resolve 'split(
fieldList, ',')' due to data type mismatch: argument 1 requires string type, however, 'fieldList' is of array type.;;
Any idea how to convert the List to String? I have tried to use .mkString() but I am missing something
Thanks