2019独角兽企业重金招聘Python工程师标准>>>
package cn.hhb.spark.sqlimport org.apache.spark.sql.{DataFrame, SQLContext}
import org.apache.spark.{SparkConf, SparkContext}/*** Created by Administrator on 2017/9/21 0021.*/
object TestSQLScala {def main(args: Array[String]) {val conf = new SparkConf().setAppName("TestSQLScala").setMaster("local").set("spark.testing.memory", "2147480000");val sc = new SparkContext(conf)val sqlContext = new SQLContext(sc)val students_df = sqlContext.read.json("c://students.json")// 打印所有数据students_df.showstudents_df.select("name", "age").showstudents_df.registerTempTable("students")sqlContext.sql("select * from students where age >= 18").show()sc.stop()}
}