创建dataframe有两种方式
-
structType
val schema = StructType(List(StructField("id", IntegerType, false),StructField("id", StringType, false))) val dataRdd = rdd.map(x => Row(x(0).toInt, x(1).toString)) sqlcontext.createDataFrame(dataRdd, schema)
2.case class Person(id:Int, name:String)
val dataRdd= rdd.map(x => Person(x(0).toInt, x(1).toString))
import sqlContext.implicits._
val df = dataRdd.toDF