Spark 2.0.x dump a csv file from a dataframe containing one array of type string

前端 未结 6 1553
难免孤独
难免孤独 2020-11-29 07:07

I have a dataframe df that contains one column of type array

df.show() looks like

|ID|ArrayOfString|Age|Gender|
+--+-------         


        
6条回答
  •  执念已碎
    2020-11-29 07:44

    CSV is not the ideal export format, but if you just want to visually inspect your data, this will work [Scala]. Quick and dirty solution.

    case class example ( id: String, ArrayOfString: String, Age: String, Gender: String)
    
    df.rdd.map{line => example(line(0).toString, line(1).toString, line(2).toString , line(3).toString) }.toDF.write.csv("/tmp/example.csv")
    

提交回复
热议问题