hive string 转数组:抽取数组中的key 然后列转行

 -- | 1110 | [{"content":"全部内容。" }, { "content":"无其它特别约定。"}] |


 select id,concat_ws('||',collect_set(content)) as contents from (
 select id, get_json_object(cl,'$.content') as content from (
 select id, split(regexp_replace( regexp_extract (property_value ,'(\\[)(.*?)(\\])',2) ,'},{','}|{'),'\\|') as property_value 
from  properties where pt='20180627000000'  and property_key ='specail'  limit 1 ) b 
 lateral view explode(property_value) tf as cl 

 ) b group by id ;  

结果 :

 +-------------------+----------+

| id | contents |
+-------------------+----------+
| 1110 | 全部内容。||无其它特别约定。 |

+-------------------+----------+

具体步骤说明:

1。 抽取树组 中的json 

2。 替换json分割符 为| 

3。split() 

4。lateral view explode(property_value)  列转行

5。行转列


是不是要疯了:好端端的一个树组 ,然后这么复杂才解析出来 ,并抽取出里面的字段 。

如果 property_value 以数组的形式存储 ,可以省掉前三步骤。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mtj66

看心情

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值