作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在表中存储了许多json数组,如下所示:
{"p_id":
{"id_type":"XXX","id":"ABC111"},
"r_ids":[
{"id_type":"HAWARE_ABCDA1","id":"dfe234fhgt"},
{"id_type":"HAWARE_CDFE2","id":"sgteth5673"}
]
}
p_id , p_id_type ,r_ids (array string), r_id_type (array string)
XXX,ABC111,[dfe234fhgt,sgteth5673],[HAWARE_ABCDA1,HAWARE_CDFE2]
select p_id
,p_id_type
,get_json_object(c.qqqq,'$.id') as r_id
,get_json_object(c.qqqq,'$.id_type') as r_id_type
from
(
select p_id
,p_id_type
,qqqq
from
(
select
get_json_object(a.main_pk,'$.id_type') as p_id_type
,get_json_object(a.main_pk,'$.id') as p_id
,split(regexp_replace(regexp_replace(a.r_ids,'\\}\\,\\{','\\}\\;\\{'),'\\[|\\]',''),'\\;') as yyyy
from
(
select
get_json_object(json_string,'$.p_id') as main_pk
,get_json_object(json_string, '$.r_ids') as r_ids
from sample_table limit 10
) a
) b lateral view explode(b.yyyy) yyyy_exploded as qqqq
)c
最佳答案
如果使用JsonSerDe
,将更容易解决复杂的数据类型。
我在这里举一个小例子,您可以使用以下方法解决:
CREATE TABLE table_json (
p_id struct<id_type:string,
id:string,
r_ids:array<struct<id_type:string,
id:string>>>
)
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe';
LOAD DATA LOCAL INPATH '<path>/your_file.json'
OVERWRITE INTO TABLE table_json;
关于json - 将Json数据拆分为array <string>列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27564516/
我是一名优秀的程序员,十分优秀!