当前位置:网站首页>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
详细解释连接参考我之前写的文章
边栏推荐
- JS动画函数封装
- RobotFramework 之 Evaluate
- GIN Bind mode to get parameters and form validation
- pytest 之 fixture参数化
- javscript基础易错点集合
- 什么是布隆过滤器?如何使用?
- Professor Chen Qiang's "Machine Learning and R Application" course Chapter 14 Assignment
- JS本地存储 sessionStorage和localStorage
- 分布式系统关注点(8)——99%的人都能看懂的「熔断」以及最佳实践 (转载非原创)
- 面试攻略系列(四)-- 你不知道的大厂面试
猜你喜欢
随机推荐
【奖励公示】第23期 2022年7月奖励名单公示:社区明星评选 | 新人奖 | 博客同步 | 推荐奖
RobotFramework 之 RF变量与标准库关键字使用
PO、DO、TO、VO、DO、DTO、DAO、POJO都是什么?
蓝桥历届真题-跑步锻炼
ArcEngine(十)创建矢量图层
Realization of RTSP Protocol
NC193 二叉树的前序遍历
Q_06_02 类型模型
记录本项目中用到的系统调用与C库函数-2
现在40系显卡都快出来了,为何1060型号的显卡还有这么多人用?
FFmpeg相机花屏花图问题解决方法
JS动画函数封装
JS本地存储 sessionStorage和localStorage
Q_04_06 把它放在一起:传送
puzzle(016.5)逻辑电路
IDEA Gradle 常遇问题(一)
万物皆可柯里化的 Ramda.js
2.微服务'黑话'集锦及Eureka注册中心相关概念
Q_06_03 表达式
Uni - app - uview Swiper shuffling figure component, click on the links to jump (click to get the item after the row data, remove data operation)