I have dataframe df
| name| languagesAtSchool|currentState|
+----------------+------------------+------------+
| James,,Smith|[Java, Scala, C++]| CA|
| Michael,Rose,|[Spark, Java, C++]| NJ|
|Robert,,Williams| [CSharp, VB, R]| NV|
+----------------+------------------+------------+
I want
+----------------+--------+-----+
|Name |language|State|
+----------------+--------+-----+
|James,,Smith |Java |CA |
|James,,Smith |Scala |CA |
|James,,Smith |C++ |CA |
|Michael,Rose, |Spark |NJ |
|Michael,Rose, |Java |NJ |
|Michael,Rose, |C++ |NJ |
|Robert,,Williams|CSharp |NV |
|Robert,,Williams|VB |NV |
|Robert,,Williams|R |NV |
+----------------+--------+-----+
I have tried the below which works perfectly
val df2=df.flatMap(f=> f.getSeq[String](1).map((f.getString(0),_,f.getString(2))))
.toDF("Name","language","State")
but I want something works without specifing other columns to keep, thus I tried
val df2 = df.withColumn("laguage", df.flatMap(f=>f.getSeq[String](1)))
Then it gives
Unknown Error: <console>:40: error: missing parameter type
val df3 = df.withColumn("laguage", df.flatMap(f=>f.getSeq[String](1)))
^
Therefore I want something in Spark to transform a column without discarding others. I guess the reason is that scala is unable to determine the type, but I cannot fix it. I'm new to scala and thanks for your help!