当前位置:网站首页>The Spark of Sql join on the and and where
The Spark of Sql join on the and and where
2022-08-01 23:36:00 【Nanfeng knows my intentions】
需求
How to achieve the above requirements.先给出结论: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
For a detailed explanation of the connection, please refer to the article I wrote earlier
边栏推荐
猜你喜欢
经典文献阅读之--DLO
企业防护墙管理,有什么防火墙管理工具?
cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
Quartus 使用 tcl 文件快速配置管脚
When solving yolov5 training: "AssertionError: train: No labels in VOCData/dataSet_path/train.cache. Can not train"
UML diagram of soft skills
Codeforces CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!) A-D Solution
Secondary Vocational Network Security Competition B7 Competition Deployment Process
测试岗月薪5-9k,如何实现涨薪到25k?
System availability: 3 9s, 4 9s in SRE's mouth... What is it?
随机推荐
GIF制作-灰常简单的一键动图工具
chrome copies the base64 data of an image
npm npm
分享10套开源免费的高品质源码,免费源码下载平台
Avoid , ,
, and tagsSpark Sql之union
How to use pywinauto and pyautogui to link the anime lady and sister please go home
numpy.isclose
JAX-based activation function, softmax function and cross entropy function
Getting started with IDEA is enough to read this article
Convert LocalDateTime to Date type
vscode hide menu bar
Calculate the midpoint between two points
npm npm
numpy.hstack
Nacos配置中心之加载配置
[Camp Experience Post] 2022 Cybersecurity Summer Camp
Chapter 12 End-User Task As Shell Scripts
cdh的hue上oozie启动报错,Cannot allocate containers as requested resource is greater than maximum allowed
计算两点之间的距离