2017-09-19 79 views
0

JSON數據是這樣的:錯誤在蜂巢加載JSON數據時

{"id":"U101", "name":"Rakesh", "place":{"city":"MUMBAI","state":"MAHARASHTRA"}, "age":20, "occupation":"STUDENT"} 
{"id":"","name":"Rakesh", "place":{"city":"MUMBAI","state":"MAHARASHTRA"}, "age":20, "occupation":"STUDENT"} 
{"id":"U103", "name":"Rakesh", "place":{"city":"","state":""}, "age":20, "occupation":"STUDENT"} 

我收到以下錯誤,而從表中試圖select數據:

hive (ecom)> select * from users_info_raw; 
OK 
Failed with exception java.io.IOException:org.apache.hadoop.hive.serde2.SerDeException: 
org.codehaus.jackson.JsonParseException: Unexpected character ('2' 
(code 50)): was expecting comma to separate OBJECT entries at 
[Source: [email protected]; line: 1, column: 222] 
Time taken: 0.144 seconds 

創建表DDL查詢:

CREATE TABLE users_info_raw(
     > id string, 
     > name string, 
     > place struct<city:string,state:string>, 
     > age INT, 
     > occupation string 
     >) 
     > ROW FORMAT SERDE 
     > 'com.cloudera.hive.serde.JSONSerDe' 
     > STORED AS INPUTFORMAT 
     > 'org.apache.hadoop.mapred.TextInputFormat' 
     > OUTPUTFORMAT 
     > 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'; 
+1

廣場20歲,希望這能解決您的問題。 – idiotduffer

回答

1

我已經使用hive hcatalog serde,它對你的輸入數據工作正常。

CREATE TABLE info_raw( id string, name string, place struct<city:string,state:string>, age INT, occupation string ) ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe' STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat';在雙引號 「20」

enter image description here