当前位置:网站首页>Spark Sql之join on and和where
Spark Sql之join on and和where
2022-08-09 13:11:00 【南风知我意丿】
需求
如何实现上图需求。先给出结论:join whre
join where
val df1: DataFrame = sc.makeRDD(Seq((1, "xm"), (2, "xl"), (3, "xw"))).toDF("id", "name")
df1.show()
df1.createOrReplaceTempView("t1")
val df2: DataFrame = sc.makeRDD(Seq(1,2)).toDF("id")
df2.createOrReplaceTempView("t2")
df2.show()
println("------------------------where------------------------------------")
val sql1:String =
s""" |select t1.id,t1.name from t1 |left join t2 |on t1.id = t2.id |where t2.id is NULL |""".stripMargin
session.sql(sql1).show()
+---+----+
| id|name|
+---+----+
| 1| xm|
| 2| xl|
| 3| xw|
+---+----+
+---+
| id|
+---+
| 1|
| 2|
+---+
------------------------where------------------------------------
+---+----+
| id|name|
+---+----+
| 3| xw|
+---+----+
join and
println("------------------------and------------------------------------")
val sql2:String =
s""" |select t1.id,t1.name from t1 |left join t2 |on t1.id = t2.id |and t2.id is NULL |""".stripMargin
session.sql(sql2).show()
------------------------and------------------------------------
+---+----+
| id|name|
+---+----+
| 1| xm|
| 2| xl|
| 3| xw|
+---+----+
原因分析
sql执行顺序:
FROM
ON
JOIN
WHERE
GROUP BY
WITH CUBE or WITH ROLLUP
HAVING
SELECT
DISTINCT ORDER BY TOP
详细解释连接参考我之前写的文章
边栏推荐
猜你喜欢
随机推荐
机器学习web服务化实战:一次吐血的服务化之路 (转载非原创)
笔试题记录~~
Professor Chen Qiang's "Machine Learning and R Application" course Chapter 13 Assignment
FFmpeg av_interleaved_write_frame错误
NC161 二叉树的中序遍历
NC192 二叉树的后序遍历
什么是布隆过滤器?如何使用?
RobotFramework 之 数据驱动
32位机器和64位机器基本数据类型长度
pyhook3简单应用(1)--实现截图保存功能
富媒体在客服IM消息通信中的秒发实践
IDEA Gradle 常遇问题(二)(持续更新)
vim常用命令
技嘉显卡 RGBFusion 不能调光解决方法
pyautogui的简单操作(2)-弹窗操作
JS动画函数封装
蓝桥历届真题-蛇形填数
RobotFramework 之 资源文件
pytest 之 fixture的定义及作用域
Process/Thread related in Sandbox - 1