2017-08-09 66 views
2

我是HIVE新手,需要一些幫助來查詢我從JSON文件創建的表格。EOF異常查詢JSON上的Hive

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 Exception

java.lang.Exception的:org.apache.hive.service.cli.HiveSQLException:錯誤在編譯聲明:失敗:ParseException的線4:17失蹤EOF在 '(' 近 'GET_JSON_OBJECT'

回答

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的列添加別名。