hive实现json数组拆解
程序员文章站
2022-03-01 22:29:57
...
PAYCHANNELDETAIL表中间字段acquire_type是json格式如下
下面是数据拆解操作
查询结果如下:
json属性拆解
[{"payAmount":"375000","payChannelCode":"BOC"},{"payAmount":"376000","payChannelCode":"ABC"}]
下面是数据拆解操作
select pay_order_id,tag1,bill_date from ( select pay_order_id,substr(acquire_type,2,length(acquire_type)-2) tags,bill_date from dd.PAYCHANNELDETAIL ) ta lateral view explode(split(tags, '},')) r1 as tag1 ;
查询结果如下:
1603150000007617360 {"payAmount":"375000","payChannelCode":"BOC"} 2016-03-15 1603150000007617360 {"payAmount":"376000","payChannelCode":"ABC"} 2016-03-15
json属性拆解
SELECT pay_order_id, get_json_object(subjson,'$.payAmount') as payAmount, get_json_object(subjson,'$.payChannelCode') as payChannelCode, bill_date FROM dd.PAYCHANNELDETAIL_SUBJSON
下一篇: Maven编写archeType小问题