Hive_解析 get_json_object ( )


Hive_解析 get_json_object ( )
 
get_json_object ( string json_string, string path )
說明: 
  • 第一個參數填寫json對象變量,第二個參數使用$表示json變量標識,然后用 . 或 [] 讀取對象或數組。
  • 如果輸入的json字符串無效,那么返回NULL。 
  • 每次只能返回一個數據項。
舉例: 
data 為 test表中的字段,數據結構如下:
data = { "store": { "fruit":[{"weight":8,"type":"apple"}, {"weight":9,"type":"pear"}], "bicycle":{"price":19.95,"color":"red"} }, "email":"amy@only_for_json_udf_test.net", "owner":"amy" }
1. get 單層值
hive> select  get_json_object(data, '$.owner') from test; 結果:amy
 
2. get 多層值
hive> select  get_json_object(data, '$.store.bicycle.price') from test; 結果:19.95
3. get 數組值[]
hive> select  get_json_object(data, '$.store.fruit[0]') from test; 結果:{"weight":8,"type":"apple"}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM