2017-04-17 38 views
0

我在查詢json數據時遇到了一些問題。配置單元中的JSON解析問題

我的樣本數據的樣子......

{ 「舍入類型」:{ 「版本」: 「1」, 「OS」: 「MS」, 「類型」: 「NS」,「車輛「:」 MH-3412" , 「MOD」:{ 「版本」:[{ 「ABC」:{ 「XYZ」: 「123.dfer」, 「方正」: 「3.0」, 「GHT」: 「佛羅里達」 「fashion」:「fg45」,「cdc」:「new」,「dof」:「yes」,「ts」:「2000-04-01T00:00:00.171Z」}}]}}}

{ 「舍入類型」:{ 「VER」: 「1」, 「OS」: 「MS」, 「類型」: 「NS」, 「車輛」: 「MH-3412」, 「MOD」:{ 「版本」:[ { 「GAP」:{ 「GGG」: 「123.dfer」, 「FFF」: 「3.0」, 「DDD」: 「佛羅里達」, 「GOP」: 「fg45」, 「CDC」: 「QQQ」,「ZZZ 「:」是「,」ts「:」2000-04-01T00:00:00.171Z「}}]}}}

{」舍入類型 「:{」 VER 「:」 1" , 「OS」: 「MS」, 「類型」: 「NS」, 「車輛」: 「MH-3412」, 「MOD」:{ 「版本」:[{」 BOX 「:{」 FRG 「:」 123.dfer」, 「CXD」: 「3.0」, 「傳真」: 「佛羅里達」, 「陝柴重工」: 「fg45」, 「CDC」: 「新」, 「自由度」: 「是的」, 「TS」: 「2000-04-01T00:00:00.171Z」}}]}}}

我做follwing

創建表SRC(myjson字符串);插入到src值中 ('{「Rtype」:{「ver」:「1」,「os」:「ms」,「type」:「ns」,「vehicle」:「Mh-3412」 「MOD」:{ 「版本」:[{ 「ABC」:{ 「XYZ」: 「123.dfer」, 「方正」: 「3.0」, 「GHT」: 「佛羅里達」, 「時尚」: 「fg45」 ,「cdc」:「new」,「dof」:「yes」,「ts」:「2000-04-01T00:00:00.171Z」}}]}}}') ,('{「Rtype」 { 「VER」: 「1」, 「OS」: 「MS」, 「類型」: 「NS」, 「車輛」: 「MH-3412」, 「MOD」:{ 「版本」:[{ 「GAP」: { 「XVY」: 「123.dfer」, 「FAH」: 「3.0」, 「GHT」: 「佛羅里達」, 「時尚」: 「fg45」, 「CDC」: 「新」, 「自由度」: 「是的」 ,「ts」:「2000-04-01T00:00:00.171Z」}}]}}}') ,('{「Rtype」:{「ver」:「1」,「os」:「ms」 , 「類型」: 「NS」, 「車輛」: 「MH-3412」, 「MOD」:{ 「版本」:[{ 「BOX」:{ 「VOG」: 「123.dfer」, 「FAH」:」 3.0" , 「傳真」: 「佛羅里達」, 「時尚」: 「fg45」, 「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
沒有where條件也countvalue 2345這是問題

我所看到的觀察結果是由於它試圖獲取的數據是$.Rtype.MOD.Version[0].GAP

回答

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) 
+0

請加解釋你的答案 –

+0

上述問題的查詢是錯誤的,他們給了其中一個錯誤的地點條款,如果他給where子句(來自SRC後),如 那麼他會得到精確的輸出 '選擇get_json_object( myjson,'$。Rtype.MOD.Version [0] .ABC.fashion')FROM src where get_json_object(myjson,'$。Rtype.MOD.Version [0] .ABC')is not null' – overflow