我是HIVE的新手,需要一些帮助来查询我从JSON
文件创建的表格。
CREATE TABLE json_table( json string);
LOAD DATA INPATH '/path/to/file.json'
INTO TABLE json_table;
当我用:
查询创建的json_table.json时SELECT * FROM json_table;
返回:
{"id":243379853,"sampling_rate":null,"timestamp":"2017-08-06 20:05:02","location":{"id":1296,"latitude":"49.863","longitude":"8.651","country":"DE"},"sensor":{"id":2573,"pin":"7","sensor_type":{"id":9,"name":"DHT22","manufacturer":"various"}},"sensordatavalues":[{"id":559959584,"value":"19.00","value_type":"temperature"},{"id":559959585,"value":"86.00","value_type":"humidity"}]}
我正在尝试获得像
这样的结果id | timestampt | | [...] |
==========|======================|=======|
243379853 | 2017-08-06 20:05:02 | [...] |
带有查询
SELECT
GET_JSON_OBJECT(json_table.json,'$.id'),
GET_JSON_OBJECT(json_table.json,'$.timestamp')
GET_JSON_OBJECT(json_table.json,'$.sampling_rate')
GET_JSON_OBJECT(json_table.json,'$.location.latitude')
GET_JSON_OBJECT(json_table.json,'$.location.longitude')
FROM json_table;
但我得到以下Hive SQL Exception
java.lang.Exception:org.apache.hive.service.cli.HiveSQLException:编译语句时出错:FAILED:ParseException line 4:17 EOF at'('near'GET_JSON_OBJECT'
答案 0 :(得分:1)
您需要添加逗号:
SELECT
GET_JSON_OBJECT(json_table.json,'$.id'),
GET_JSON_OBJECT(json_table.json,'$.timestamp'), --here
GET_JSON_OBJECT(json_table.json,'$.sampling_rate'), --here
GET_JSON_OBJECT(json_table.json,'$.location.latitude'), -- and here
GET_JSON_OBJECT(json_table.json,'$.location.longitude')
FROM json_table;
我还会使用expr AS alias
为列添加别名。