Hive處理json格式資料

2021-08-13 19:25:24 字數 708 閱讀 8457

1

、資料示例

假設info表中存有兩個字段,分別是id,content

content=]}

2、使用hive內建函式

get_json_object 、 json_tuple、  regexp_replace

3、說明

使用get_json_object 解析content,獲取properties,使用regexp_replace替換掉中括號(原因是json_tuple不識別array型別),最後用json_tuple獲取properties中所需的字段

例如:獲取id,name和id_card_number

select id,t2.* from (select id, regexp_replace(get_json_object(content,"$.properties"),'\\[|\\]','') properties from info) t1

lateral view json_tuple(tt.properties,"name","id_card_number") t2 as name,id_card_number;

結果:id        t2.name     t3.id_card_number

1          jack            123456789012345678

hive處理json資料

今天練習一下在hive中使用get json object這個函式,首先建立乙個表將json格式的資料匯入 create table json01 line string 將資料匯入 load data local inpath home hadoop json test into table js...

hive處理json資料

1.載入hcatalog包,這個包已經在hive目錄檔案中 hive add jar hcatalog share hcatalog hive hcatalog core 1.2.0.jar 2.建立處理json格式資料的表 注意 org.apache.hive.hcatalog.data.json...

Hive解析json格式資料

本文將介紹兩個使用hive解析json的小demo 1.hadoop hadoop001 jsondata more rating.json 很多資料.hive hwzhdb create table parsejson jsondata string oktime taken 0.146 seco...