当前位置:网站首页>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
详细解释连接参考我之前写的文章
边栏推荐
- nodejs--process
- excel split text into different rows
- 研发团队数字化转型实践
- 系统可用性:SRE口中的3个9,4个9...到底是个什么东西?
- 伸展树的特性及实现
- 检查点是否在矩形内
- Chapter 19 Tips and Traps: Common Goofs for Novices
- Special characters & escapes in bat
- From 0 to 100: Notes on the Development of Enrollment Registration Mini Programs
- y84. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (15)
猜你喜欢
From 0 to 1: Design and R&D Notes of Graphic Voting Mini Program
The third chapter of the imitation cattle network project: develop the core functions of the community (detailed steps and ideas)
Quarantine and downgrade
Dynamic Scene Deblurring with Parameter Selective Sharing and Nested Skip Connections
文件查询匹配神器 【glob.js】 实用教程
C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
Secondary Vocational Network Security Competition B7 Competition Deployment Process
解决端口占用
【参营经历贴】2022网安夏令营
Solve the port to take up
随机推荐
深度学习基础-基于Numpy的循环神经网络(RNN)实现和反向传播训练
论文理解【RL - Exp Replay】—— Experience Replay with Likelihood-free Importance Weights
excel cell contian two words, seperated by a slash
颜色透明参数
E - Integer Sequence Fair
数据机构---第五章树与二叉树---二叉树的概念---应用题
vscode hide menu bar
C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
【好书推荐】第一本无人驾驶技术书
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
从0到1:图文投票小程序设计与研发笔记
C language - branch statement and loop statement
下载安装 vscode(含汉化、插件的推荐和安装)
Getting started with IDEA is enough to read this article
numpy.around
Calculate the angle of a line defined by two points
基于JAX的激活函数、softmax函数和交叉熵函数
Access the selected node in the console
JAX-based activation function, softmax function and cross entropy function
从0到100:招生报名小程序开发笔记