Sql 在JSON上查询配置单元时发生EOF异常
我是HIVE新手,需要一些帮助来查询从Sql 在JSON上查询配置单元时发生EOF异常,sql,json,hadoop,hive,Sql,Json,Hadoop,Hive,我是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-0
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;
但是我得到了以下配置单元SQL异常
java.lang.Exception:org.apache.hive.service.cli.HiveSQLException:编译语句时出错:失败:ParseException行4:17在“(“GET_JSON_OBJECT”附近的”缺少EOF
您需要添加逗号:
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
为列添加别名