HIVE json格式資料的處理

來源:互聯網
上載者:User

標籤:direction   apple   create   pat   bic   方法   ring   instant   from   

在hive 避免不了Jason格式的話,可以使用如下兩個函數

 

HIVE直接讀入json的函數有兩個:

(1)get_json_object(string json_string, string path)

傳回值: string  

說明:解析json的字串json_string,返回path指定的內容。如果輸入的json字串無效,那麼返回NULL。  

舉例:  

hive> select  get_json_object(‘{“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” } ‘,’$.owner’) from dual;  

結果:amy 

這個函數每次只能返回一個資料項目。

(2)json_tuple(jsonStr, k1, k2, ...)

參數為一組鍵k1,k2……和JSON字串,傳回值的元組。該方法比 get_json_object 高效,因為可以在一次調用中輸入多個鍵

select a.timestamp, b.*from log a lateral view json_tuple(a.appevent, ‘eventid‘, ‘eventname‘) b as f1, f2;

處理資料範例:
{"GPS_LAT":39.8965125,"GPS_LONG":116.3493225,"GPS_SPEED":20.9993625,"GPS_STATE":"A","GPS_TIME":"2014-01-02 00:00:16","IMEI":"508597","after_oxygen_sensor":132,"air_condion_state":3,"bdoneNo_after_mileage":0,"bdoneNo_zero_mileage":8044,"db_speed":22,"direction_angle":358.2585,"front_oxygen_sensor":64,"instant_fuel":233,"speed":1210,"torque":33,"total_fuel":0}
處理HIVE語句:
create table 2014jrtest as select json_tuple(line,‘GPS_LAT‘,‘GPS_LONG‘,‘GPS_SPEED‘,‘GPS_STATE‘,‘GPS_TIME‘,‘IMEI‘,‘after_oxygen_sensor‘,‘air_condion_state‘,‘bdoneNo_after_mileage‘,‘bdoneNo_zero_mileage‘,‘db_speed‘,‘direction_angle‘,‘front_oxygen_sensor‘,‘instant_fuel‘,‘speed‘,‘torque‘,‘total_fuel‘) from 2014test;

HIVE json格式資料的處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.