允许使用编程思维处理数据,同时结合SQL语法。
1)SQL语法:
selectx.a,x.b ④from x join y ①on x.id=y.idwhere x.xxx > xxx ②group by xxxx ③order by xxx ⑤limit x ⑥
2)编写的程序:
顺序运行
优点: 不必遵守SQL规范<br /> 缺点: 复用性差,只能在Spark中用!<br /> 额外加重学习成本
@Testdef testDSL() : Unit ={val dataFrame1: DataFrame = session.read.json("input/people.json")// DSL 不写SQL,无需映射dataFrame为一张表//dataFrame1.select("name").show()//dataFrame1.select("name","age").filter("age > 20").show()// 查询所有age > 20的员工的名称和年龄,自动为年龄+10岁// $代表,先获取age列的值import session.implicits._dataFrame1.select($"name",$"age" + 10).filter("age > 20").show()// 计算他们的平均年龄dataFrame1.agg(Map("age" -> "avg")).show()}
