scala - Spark : How to union all dataframe in loop

前端 未结 6 1680
抹茶落季
抹茶落季 2020-12-14 22:41

Is there a way to get the dataframe that union dataframe in loop?

This is a sample code:

var fruits = List(
  \"apple\"
  ,\"orange\"
  ,\"melon\"
)          


        
6条回答
  •  暖寄归人
    2020-12-14 23:11

    You could created a sequence of DataFrames and then use reduce:

    val results = fruits.
      map(fruit => Seq(("aaa", "bbb", fruit)).toDF("aCol","bCol","name")).
      reduce(_.union(_))
    
    results.show()
    

提交回复
热议问题