json在HIVE中的问题 [英] json issue in HIVE

查看:140
本文介绍了json在HIVE中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

create table src(myjson string);

 插入src值{Rtype:{ver: 1\" , OS: MS, 类型: NS, 车辆: MH-3412, MOD:{ 版本:[{ ABC:{ XYZ: 123.dfer  方正: 3.0, GHT: 佛罗里达, 时尚: fg45, CDC: 新, 自由度: 是的, TS: 2000-04-01T00:00:00.171Z },{ XYZ : 123.dfer  创建者: 2.0, GHT: 佛罗里达, 时尚: fg45, CDC : 新, 自由度: 是的, TS: 2000-04-01T00:00:00.171Z},{ XYZ: 123.dfer, 方正: 7.0 GHT: 佛罗里达, 时尚: fg45, CDC: 新, 自由度: 是的, TS: 2000-04-01T00:00:00.171Z} }]}}} US 123 

{Rtype:{ver:1,os:ms,type:ns,vehicle: MH-3412\" , MOD:{ 版本:[{ ABC:{ XYZ: 123.dfer, 方正: 3.0, GHT: 佛罗里达, 时尚 : fg45, CDC: 新, 自由度: 是的, TS: 2000-04-01T00:00:00.171Z},{ XYZ: 123.dfer 方正: 3.0, GHT: 佛罗里达, 时尚: fg45, CDC: 新, 自由度: 是的, TS:2000-04-01T00 :00:00.171Z },{ XYZ : 123.dfer, 方正: 3.0, GHT: 佛罗里达, 时尚: fg45, CDC: 新 自由度: 是的, TS: 2000-04-01T00:00:00.171Z}}]}}} CAV 12673


{Rtype:{ver:1,os: MS, 类型: NS, 车辆: MH-3412, MOD:{ 版本:[{ ABC:{ XYZ: 123.dfer,创建者: 3.0\" , GHT: 佛罗里达, 时尚: fg45, CDC: 新, 自由度: 是的, TS:2000-04-01T00:00 :00.171Z },{ XYZ : 123.dfer 方正: 3.0, GHT: 佛罗里达, 时尚: fg45, CDC: 新,自由度 : 是的 TS: 2000-04-01T00:00:00.171Z},{ XYZ: 123.dfer, 方正: 3.0, GHT: 佛罗里达州,fashion:fg45,cdc:new,dof:yes,ts:2000-04-01T00:00:00.171Z}}]}}} XR 123sd2

我需要如下所示的数据,同时进行选择
任何提示,如何实现这一目标?

  ver os XYZ创始人国家/地区号码
1 ms 123.dfer 3.0 us 123
1 ms 123。 dfer 2.0 us 123
1 ms 123.dfer 7.0.0 us 123


解决方案

您可以使用 get_js

$ {$ .Rtype.ver'),get_json_object(col,'$ .Rtype.os')


create table src (myjson string);

insert into src values {"Rtype":{"ver":"1","os":"ms","type":"ns","vehicle":"Mh-3412","MOD":{"Version":[{"ABC":{"XYZ":"123.dfer","founder":"3.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"},{"XYZ":"123.dfer","founder":"2.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"},{"XYZ":"123.dfer","founder":"7.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"}}]}}} US 123

{"Rtype":{"ver":"1","os":"ms","type":"ns","vehicle":"Mh-3412","MOD":{"Version":[{"ABC":{"XYZ":"123.dfer","founder":"3.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"},{"XYZ":"123.dfer","founder":"3.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"},{"XYZ":"123.dfer","founder":"3.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"}}]}}} CAV 12673


{"Rtype":{"ver":"1","os":"ms","type":"ns","vehicle":"Mh-3412","MOD":{"Version":[{"ABC":{"XYZ":"123.dfer","founder":"3.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"},{"XYZ":"123.dfer","founder":"3.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"},{"XYZ":"123.dfer","founder":"3.0","GHT":"Florida","fashion":"fg45","cdc":"new","dof":"yes","ts":"2000-04-01T00:00:00.171Z"}}]}}} XR 123sd2

i want data like shown below while doing select Any hint, how can acheive this ?

ver os  XYZ         founder         country     number
1   ms  123.dfer     3.0            us          123
1   ms  123.dfer     2.0            us          123
1   ms  123.dfer     7.0.0          us          123

解决方案

You can use get_json_object(col, '$.Rtype.ver'), get_json_object(col, '$.Rtype.os') with select clause from table src

这篇关于json在HIVE中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆