当前位置:网站首页>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
详细解释连接参考我之前写的文章
边栏推荐
- npm npm
- The third chapter of the imitation cattle network project: develop the core functions of the community (detailed steps and ideas)
- 如何更好的理解的和做好工作?
- 用virtualenv和Virtualenvwrapper虚拟环境管理工具创建虚拟环境
- Chapter 12 End-User Task As Shell Scripts
- PostgreSQL 基础--常用命令
- 欧拉路径与欧拉回路
- vscode hide menu bar
- 数据机构---第五章树与二叉树---二叉树的概念---应用题
- 【好书推荐】第一本无人驾驶技术书
猜你喜欢
Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
Quarantine and downgrade
请问什么是 CICD
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
伸展树的特性及实现
【SeaTunnel】从一个数据集成组件演化成企业级的服务
Secondary Vocational Network Security Competition B7 Competition Deployment Process
chrome复制一张图片的base64数据
Leetcode 129求根节点到叶节点数字之和、104二叉树的最大深度、8字符串转换整数(atoi)、82删除排序链表中的重复元素II、204二分查找、94二叉树的中序遍历、144二叉树的前序遍历
Background project Express-Mysql-Vue3-TS-Pinia page layout-sidebar menu
随机推荐
毕业作业
计算两点之间的距离
Chapter 11 Working with Dates and Times
[LeetCode304周赛] 两道关于基环树的题 6134. 找到离给定两个节点最近的节点,6135. 图中的最长环
[C language advanced] file operation (2)
Oracle database is set to read-only and read-write
cmd command
npm npm
Dynamic Scene Deblurring with Parameter Selective Sharing and Nested Skip Connections
cmd指令
img 响应式图片的实现(含srcset属性、sizes属性的使用方法,设备像素比详解)
Data Organization --- Chapter 5 Trees and Binary Trees --- The Concept of Binary Trees --- Application Questions
对于在新标签页中打开的链接,始终使用“noopener”或“noreferrer”
Nacos配置中心之加载配置
路径压缩、、
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
vscode hide menu bar
6134. Find the closest node to the given two nodes - force double hundred code
解决yolov5训练时出现:“AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train ”
npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)