作用
explode() takes in an array (or a map) as an input and outputs the elements of the array (map) as separate rows. UDTFs can be used in the SELECT expression list and as a part of LATERAL VIEW.
explode() 接收一个 array 或 map 类型的数据作为输入,然后将 array 或 map 里面的元素按照每行的形式输出。其可以配合 LATERAL VIEW 一起使用。
demo
select
explode(array('A', 'B', 'C')) as e1
输出
e |
---|
A |
B |
C |
select
explode(map('a', 1, 'b', 2, 'c', 3)) as (k, v)
输出
k | v |
---|---|
a | 1 |
b | 2 |
c | 3 |