lateral view explode实现结果:
如果不用lateral view explode,可以这样实现:
步骤:
1.将一条记录变成n条一样的记录,即
前面再带上序号值,num是key,answers[num]即为所要的value,
2. 上图的实现通过两表连接的方式,
3.B表的实现就是生成递增数字,利用space得到n个空格,在对应空格前加上序号
--方法1
select
row_number() over() as id
from
(select split(space(299), ' ') as x) t
lateral view explode(x) ex;
--方法2
select pos + 1
from
(select 1 as id_start, 300 as id_end) t
lateral view posexplode(split(space(id_end - id_start), ' ')) ex as pos, blank;
posexplode(数组) t as pos, blank,只有第一个字段有值,是位置,第二个为空,如果是map就有值