允许使用编程思维处理数据,同时结合SQL语法。
    1)SQL语法:

    1. select
    2. x.a,x.b
    3. from x join y
    4. on x.id=y.id
    5. where x.xxx > xxx
    6. group by xxxx
    7. order by xxx
    8. limit x

    2)编写的程序:
    顺序运行

    1. 优点: 不必遵守SQL规范<br /> 缺点: 复用性差,只能在Spark中用!<br /> 额外加重学习成本
    1. @Test
    2. def testDSL() : Unit ={
    3. val dataFrame1: DataFrame = session.read.json("input/people.json")
    4. // DSL 不写SQL,无需映射dataFrame为一张表
    5. //dataFrame1.select("name").show()
    6. //dataFrame1.select("name","age").filter("age > 20").show()
    7. // 查询所有age > 20的员工的名称和年龄,自动为年龄+10岁
    8. // $代表,先获取age列的值
    9. import session.implicits._
    10. dataFrame1.select($"name",$"age" + 10).filter("age > 20").show()
    11. // 计算他们的平均年龄
    12. dataFrame1.agg(Map("age" -> "avg")).show()
    13. }