suresh kumar
suresh kumar

Reputation: 1

error when loading json data in hive

JSON data looks like :

{"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"}

I get the following error while trying to select the data from the table :

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: java.io.StringReader@15b0734; line: 1, column: 222] 
Time taken: 0.144 seconds

Create Table DDL Query:

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';

Upvotes: 0

Views: 1066

Answers (1)

Dipak Shaw
Dipak Shaw

Reputation: 401

I have used hive hcatalog serde and it is working fine with your input data.

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';

enter image description here

Upvotes: 2

Related Questions