1.数据格式如下图
2.创建表并加载数据
hive (test)> create table rating_json(json string);
hive (test)> load data local inpath '/home/hadoop/testdata/json/rating.json' into table rating_json;
Loading data to table test.rating_json
Table test.rating_json stats: [numFiles=1, totalSize=63602280]
OK
Time taken: 0.68 seconds
2.使用build-in 函数json_tuple
hive (test)> desc function json_tuple;
OK
tab_name
json_tuple(jsonStr, p1, p2, ..., pn) - like get_json_object, but it takes multiple names and return a tuple. All the input parameters and output column types are string.
Time taken: 0.004 seconds, Fetched: 1 row(s)
hive (test)> select json_tuple(json,'movie','rate','time','userid') as (