配置单元

时间:2017-04-17 10:27:18

标签: json hadoop hive

我在查询json数据时遇到了一些问题。

我的示例数据看起来像......

  

{"舍入类型" {"版本":" 1"" OS":" MS&#34 ;, "类型":" NS""车辆":" MH-3412"" MOD" {&# 34;版本":[{" ABC" {" XYZ":" 123.dfer""创始人":&# 34; 3.0"" GHT":"佛罗里达""时尚":" fg45"" CDC&# 34;:"新""自由度":"是"" TS":" 2000-04-01T00:00 :00.171Z"}}]}}}

     

{"舍入类型" {"版本":" 1"" OS":" MS&#34 ;, "类型":" NS""车辆":" MH-3412"" MOD" {&# 34;版本":[{" GAP" {" GGG":" 123.dfer"" FFF":&# 34; 3.0"" DDD":"佛罗里达"" GOP":" fg45"" CDC&# 34;:" QQQ"" ZZZ":"是"" TS":" 2000-04-01T00:00 :00.171Z"}}]}}}

     

{"舍入类型" {"版本":" 1"" OS":" MS&#34 ;, "类型":" NS""车辆":" MH-3412"" MOD" {&# 34;版本":[{" BOX" {" FRG":" 123.dfer"" CXD":&# 34; 3.0"" FAX":"佛罗里达"" SXD":" fg45"" CDC&# 34;:"新""自由度":"是"" TS":" 2000-04-01T00:00 :00.171Z"}}]}}}

我做了以下

  

create table src(myjson string);

     

插入src值       (' {"舍入类型" {"版本":" 1"" OS":" MS&#34 ;,"类型":" NS""车辆":" MH-3412"" MOD":{ "版本":[{" ABC" {" XYZ":" 123.dfer""创始人&#34 ;: " 3.0"" GHT":"佛罗里达""时尚":" fg45"" CDC":"新""自由度":"是"" TS":" 2000-04-01T00 :00:00.171Z"}}]}}}')   ,(' {"舍入类型" {"版本":" 1"" OS":" MS&# 34;,"类型":" NS""车辆":" MH-3412"" MOD&#34 ;: {"版本":[{" GAP" {" XVY":" 123.dfer"" FAH" :" 3.0"" GHT":"佛罗里达""时尚":" fg45"&#34 ; CDC":"新""自由度":"是"" TS":" 2000-04- 01T00:00:00.171Z"}}]}}}')   ,(第39; {"舍入类型" {"版本":" 1"" OS":" MS&# 34;,"类型":" NS""车辆":" MH-3412"" MOD&#34 ;: {"版本":[{" BOX" {" VOG":" 123.dfer"" FAH" :" 3.0"" FAX":"佛罗里达""时尚":" fg45"&#34 ; CDC":"新""自由度":"是"" TS":" 2000-04- 01T00:00:00.171Z"}}]}}}')   ;

问题是当我开始做select get_json_object(myjson,'$.Rtype.MOD.Version[0].ABC.fashion') where get_json_object(myjson,'$.Rtype.MOD.Version[0].ABC') is not null from src

我正在为某些字段获取NULLS

计算这个值为2345的价值 没有条件也计数值2345.这是问题

我所看到的观察是因为它试图获取$.Rtype.MOD.Version[0].GAP

的数据

1 个答案:

答案 0 :(得分:0)

hive> load data local inpath '/home/satish/s.json' into table sjson;

Loading data to table hivelearning.sjson
Table hivelearning.sjson stats: [numFiles=1, totalSize=216]

hive> select * from sjson;

{"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"}}]}}}

Time taken: 1.297 seconds, Fetched: 1 row(s)

hive> select get_json_object(data,'$.Rtype.MOD.Version[0].ABC.fashion') from sjson;

OK

fg45

Time taken: 0.084 seconds, Fetched: 1 row(s)