- 使用sparkSession代替sparkContext
- sparkSession读各种源:
- 读文件:val peopleDf = spark.read.textFile("E:\\07-hadoop\\01-spark\\sql\\people.txt")
- df转rdd : val peopleDs = peopleDf.rdd
- 将rdd变换为一行一行:
val peopleRdd = peopleDs.map(line => Row(line.split(",")(0), line.split(",")(1).toInt)) - 通过rdd和schema 创建临时表 spark.createDataFrame(peopleRdd,schema).createOrReplaceTempView("people")
- 使用sql查询临时表:val peopleSqlDf = spark.sql("select * from people")
- 两个dateFrame之间join等操作:
val rdd =
locationSqlDf.join(peopleSqlDf,locationSqlDf("name") === peopleSqlDf("name")).drop(locationSqlDf("name")).toDF()