我的蜂巢表如下:
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’;
有没有办法分解产品字段,以便它将url,name,user_id存储到三个不同的列中?
有人可以建议我就同一件事....
答案 0 :(得分:1)
您应该能够按如下方式爆炸三个阵列
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
;