赞
踩
{“id”:1, “name”:“Ella”, “age”:36}
{“id”:2, “name”:“Bob”, “age”:29}
{“id”:3, “name”:“Jack”, “age”:29}
{“id”:4, “name”:“Jim”, “age”:28}
{“id”:4, “name”:“Jim”, “age”:28}
{“id”:5, “name”:“Damon”}
{“id”:5, “name”:“Damon”}
创建sparksession 或 sparkcontext sqlContext
val conf = new SparkConf().setAppName("testSparkSql").setMaster("local[2]")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
val spark = new SparkSession.builder().getOrCreate()
创建 dataframe val df = sqlContext.read.json("F:/test/employee.json")
df.show()
df.distinct().show()
df.drop("id").show()
df.filter(df("age") > 30).show()
df.groupBy(df("age")).count().show()
df.sort(df("name").asc).show()
df.show(3)
df.select(df("name").as("username")).show()
df.agg("age" -> "avg").show()
df.agg("age" -> "min").show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。