如何将配置单元的explode()函数用于复杂结构?

sr4lhrrt  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(283)

我的Hive表如下所示:

CREATE EXTERNAL TABLE sample(id STRING,products STRUCT<urls:ARRAY<STRUCT<url:STRING>>,product_names:ARRAY<STRUCT<name:STRING>>,user:ARRAY<STRUCT<user_id:STRING>>>)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
STORED AS TEXTFILE
LOCATION ‘/user/input/sample’;

有没有办法分解products字段,以便它将url、name、userid存储到三个不同的列中?
有谁能给我建议一下同样的。。。。

qcuzuvrc

qcuzuvrc1#

你应该能够分解你的三个数组,如下所示

select url, product_name, user_id from sample
lateral VIEW explode(products.urls) A as url
lateral VIEW explode(products.product_names) B as product_name
lateral VIEW explode(products.user) C as user_id

;

相关问题