10.6 使用 IDEA 创建 SparkSQL 程序
步骤1: 添加 SparkSQL 依赖
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.1.1</version>
</dependency>
步骤2: 具体代码
package day05
object DataFrameDemo {
def main(args: Array[String]): Unit = {
val spark: SparkSession = SparkSession.builder()
.master("local[*]")
.appName("Word Count")
.getOrCreate()
val df = spark.read.json("file://" + ClassLoader.getSystemResource("user.json").getPath)
df.show
df.filter($"age" > 19).show
df.createTempView("user")
spark.sql("select * from user where age > 19").show
spark.stop()
}
}