object CreateDatasetByToDs {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("demo01").setMaster("local[*]")
val session = SparkSession.builder().config(conf).getOrCreate()
// 通过集合的toDS()创建Dataset
import session.implicits._
val seq: Seq[Teacher] = Array(Teacher("zs", 20), Teacher("ls", 30))
val dataset: Dataset[Teacher] = seq.toDS()
dataset.show()
// 通过rdd的toDS()创建Dataset
import session.implicits._
val rdd: RDD[Teacher] = session.sparkContext.makeRDD(seq)
val dataset1 = rdd.toDS()
dataset1.show()
}
}
case class Teacher(@BeanProperty var name: String, @BeanProperty age: Int)
标签:toDS,seq,val,创建,Dataset,session,Teacher
From: https://www.cnblogs.com/jsqup/p/16639024.html