首先,使用样例类: 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
目录 Part I. Gentle Overview of Big Data and Spark Overview 1.基本架构 2.基本概念 3.例子(可跳过) Spark工具箱 1.Datasets: Type-Safe Structured APIs 2.Structured Streaming 3.Machine Learning and Advanced Analytics 4.Lower-Level APIs Part II. Structured APIs-DataFrames,
#构造case class,利用反射机制隐式转换 scala> import spark.implicits._ scala> val rdd= sc.textFile("input/textdata.txt") scala> case class Person(id:Int,name:String) scala> val df = rdd.map(_.split(",")).map(x=>Person(x(0).toInt,x(1))