设为首页 加入收藏

TOP

hive string 转数组:抽取数组中的key 然后列转行
2018-12-01 01:14:28 】 浏览:830
Tags:hive string 抽取 key 然后 转行
版权声明:本文为博主原创文章,未经博主允许随机转载。 https://blog.csdn.net/mtj66/article/details/80849106

-- | 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 以数组的形式存储 ,可以省掉前三步骤。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇hive 数字长度控制 下一篇大数据的仓库Hive学习(一)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目