标签:数据 create app info new ddt taf src tty
1、通过case class方式创建
people.txt
//定义case class,相当于表结构 case class People(var name:String,var age:Int) object TestDataFrame1 { def main(args: Array[String]): Unit = { val conf = new SparkConf().setAppName("RDDToDataFrame").setMaster("local") val sc = new SparkContext(conf) val context = new SQLContext(sc) // 将本地的数据读入 RDD, 并将 RDD 与 case class 关联 val peopleRDD = sc.textFile("E:\\666\\people.txt") .map(line => People(line.split(",")(0), line.split(",")(1).trim.toInt)) import context.implicits._ // 将RDD 转换成 DataFrames val df = peopleRDD.toDF //将DataFrames创建成一个临时的视图 df.createOrReplaceTempView("people") //使用SQL语句进行查询 context.sql("select * from people").show() } }
2、通过structType方式创建
3、通过json文
参考博客:https://www.cnblogs.com/frankdeng/p/9301743.html
标签:数据 create app info new ddt taf src tty
原文地址:https://www.cnblogs.com/guoyu1/p/12092353.html