首页 > 其他分享 >通过toDS()方法创建Dataset

通过toDS()方法创建Dataset

时间:2022-08-30 13:58:27浏览次数:46  
标签:toDS seq val 创建 Dataset session Teacher

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

相关文章