jam*_*iet 6 apache-spark apache-spark-sql spark-dataframe
Spark SQL文档指定join()支持以下联接类型:
必须是以下之一:内部,交叉,外部,完整,完整_外部,左,左_外部,右,右_外部,左_半和left_anti。
有什么区别outer和full_outer?我怀疑不是,我怀疑它们只是彼此的同义词,但想弄清楚。
Spark v2.4.0 连接代码(_ 已被抑制):
case "inner" => Inner
case "outer" | "full" | "fullouter" => FullOuter
case "leftouter" | "left" => LeftOuter
case "rightouter" | "right" => RightOuter
case "leftsemi" => LeftSemi
case "leftanti" => LeftAnti
case "cross" => Cross
Run Code Online (Sandbox Code Playgroud)
所以 Spark 确实支持:Inner、FullOuter、LeftOuter、RightOuter、LeftSemi、LeftAnti 和 Cross。
简单的例子,给出:
+---+-----+
| id|value|
+---+-----+
| 1| A1|
| 2| A2|
| 3| A3|
| 4| A4|
+---+-----+
Run Code Online (Sandbox Code Playgroud)
和:
+---+-----+
| id|value|
+---+-----+
| 3| A3|
| 4| A4|
| 4| A4_1|
| 5| A5|
| 6| A6|
+---+-----+
Run Code Online (Sandbox Code Playgroud)
你得到:
外连接
+----+-----+----+-----+
| id|value| id|value|
+----+-----+----+-----+
|null| null| 5| A5|
|null| null| 6| A6|
| 1| A1|null| null|
| 2| A2|null| null|
| 3| A3| 3| A3|
| 4| A4| 4| A4|
| 4| A4| 4| A4_1|
+----+-----+----+-----+
Run Code Online (Sandbox Code Playgroud)
FULL_OUTER 连接
+----+-----+----+-----+
| id|value| id|value|
+----+-----+----+-----+
|null| null| 5| A5|
|null| null| 6| A6|
| 1| A1|null| null|
| 2| A2|null| null|
| 3| A3| 3| A3|
| 4| A4| 4| A4|
| 4| A4| 4| A4_1|
+----+-----+----+-----+
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1416 次 |
| 最近记录: |