爆炸和爆炸外的区别 [英] Difference between explode and explode_outer

查看:25
本文介绍了爆炸和爆炸外的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

explode 有什么区别explode_outer?这两个函数的文档是相同的,两个函数的示例也相同:

What is the difference between explode and explode_outer? The documentation for both functions is the same and also the examples for both functions are identical:

SELECT explode(array(10, 20));
 10
 20

SELECT explode_outer(array(10, 20));
 10
 20

Spark 源 表明这两个函数之间存在差异

The Spark source suggests that there is a difference between the two functions

expression[Explode]("explode"),
expressionGeneratorOuter[Explode]("explode_outer")

但是expressionGeneratorOuter表达式?

推荐答案

explode 通过忽略数组中的空值或空值,为数组或映射列中的每个元素创建一行,而 explode_outer 返回数组或映射中的所有值,包括 null 或空.

explode creates a row for each element in the array or map column by ignoring null or empty values in array whereas explode_outer returns all values in array or map including null or empty.

例如,对于以下数据框-

For example, for the following dataframe-

id | name | likes
_______________________________
1  | Luke | [baseball, soccer]
2  | Lucy | null

explode 给出以下输出-

id | name | likes
_______________________________
1  | Luke | baseball
1  | Luke | soccer

explode_outer 给出以下输出-

id | name | likes
_______________________________
1  | Luke | baseball
1  | Luke | soccer
2  | Lucy | null


SELECT explode(col1) from values (array(10,20)), (null)

返回

+---+
|col|
+---+
| 10|
| 20|
+---+

同时

SELECT explode_outer(col1) from values (array(10,20)), (null)

返回

+----+
| col|
+----+
|  10|
|  20|
|null|
+----+

这篇关于爆炸和爆炸外的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆