当前位置:网站首页>Spark Sql之join on and和where
Spark Sql之join on and和where
2022-08-01 23:23: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
详细解释连接参考我之前写的文章
边栏推荐
猜你喜欢
随机推荐
用virtualenv和Virtualenvwrapper虚拟环境管理工具创建虚拟环境
伸展树的特性及实现
Check if point is inside rectangle
color transparency parameter
Additional Features for Scripting
TCP 可靠吗?为什么?
qt-faststart 安装使用
SQL Server (design database--stored procedure--trigger)
Additional Features for Scripting
When using DocumentFragments add a large number of elements
还在纠结报表工具的选型么?来看看这个
How to better understand and do a good job?
6133. 分组的最大数量
sys_kill系统调用
Dynamic Scene Deblurring with Parameter Selective Sharing and Nested Skip Connections
visual studio code multiple editing
perspectiveTransform warpPerspective getPerspectiveTransform findHomography
访问控制台中的选定节点
vscode hide menu bar
Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历









