当前位置:网站首页>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
边栏推荐
- chrome copies the base64 data of an image
- Flink学习第三天——一文带你了解什么是Flink流?
- Chapter 19 Tips and Traps: Common Goofs for Novices
- The third chapter of the imitation cattle network project: develop the core functions of the community (detailed steps and ideas)
- PostgreSQL 基础--常用命令
- 数据库表设计规则
- Secondary Vocational Network Security Competition B7 Competition Deployment Process
- CDH6的Hue打开出现‘ascii‘ codec can‘t encode characters
- 程序员还差对象?new一个就行了
- Oracle 数据库设置为只读及读写
猜你喜欢

云原生DevOps环境搭建

Flink学习第三天——一文带你了解什么是Flink流?

C#大型互联网平台管理框架源码:基于ASP.NET MVC+EF6+Bootstrap开发,支持多数据库
![[C language advanced] file operation (2)](/img/4d/49d9603aeed16f1600d69179477eb3.png)
[C language advanced] file operation (2)

Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training

一款简洁的文件传输工具

获取小猪民宿(短租)数据

6134. 找到离给定两个节点最近的节点-力扣双百代码

伸展树的特性及实现

How do programmers solve online problems gracefully?
随机推荐
几道关于golang并发的面试题
访问控制台中的选定节点
6133. 分组的最大数量
中职网络安全竞赛B7比赛部署流程
LocalDateTime转为Date类型
毕业作业
辛普森悖论
numpy.around
numpy.unique
problem solved
TCP 可靠吗?为什么?
数据机构---第五章树与二叉树---二叉树的概念---应用题
numpy.isclose
经典文献阅读之--DLO
Additional Features for Scripting
B. Difference Array--Codeforces Round #808 (Div. 1)
Deep Learning Fundamentals - Numpy-based Recurrent Neural Network (RNN) implementation and backpropagation training
IDEA入门看这一篇就够了
软技能之UML图
Is TCP reliable?Why?