1. 创建表
CREATE TABLE tmp_json_test (
appkey string,
json string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
STORED AS textfile ;
2. 导入数据,样例如下:
load data local inpath '/home/jb-gongmingfeng/test_data.log' overwrite into table tmp_json_test;
数据内容如下
appkey001|{"count":2,"usage":91273,"pkg":"com.example.gotest"}
appkey001|{"count":234,"usage":9876,"pkg":"com.example.gotest"}
appkey001|{"count":34,"usage":5432,"pkg":"com.example.msg"}
3. 读取json的数据有两种方法。
方法一:
select t.appkey , get_json_object(t.json,'$.count'), get_json_object(t.json,'$.usage') from tmp_json_test t ;
方法