sparksql Seq生成DataFrame

首先,使用样例类:

case class User(id:Int,name: String,gender:String, age: Int)

之后使用Seq创建Dataframe

val alice: User = User(3, "Alice", "F", 26)
val tom: User = User(4, "Tom", "M", 23)
val df: DataFrame = spark.createDataFrame(Seq(alice, tom))

 

posted @ 2022-02-16 22:13  睡觉不困  阅读(447)  评论(0编辑  收藏  举报