1. 自定义数据生成查询表
package com.zz.spark.sparksql
import org.apache.spark.sql.{DataFrame, SparkSession}
/**
* 自定义DataFrame注册成数据表,查询数据表
*/
object Demo1 {
def main(args: Array[String]): Unit = {
val spark = SparkSession.builder()
.appName("Demo1")
.master("local")
.getOrCreate()
val df: DataFrame = spark.createDataFrame(
Seq(("zhangsan", 22), ("lisi", 33), ("wangwu", 44))
).toDF("name", "age")
df.show()
df.createTempView("t_user")
val result: DataFrame = spark.sql("select * from t_user where age=33")
result.show()
spark.close()
}
}
1.1 目录结构&本地运行
|