欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

hive实现json数组拆解

程序员文章站 2022-03-01 22:29:57
...
PAYCHANNELDETAIL表中间字段acquire_type是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
相关标签: json hive