rcongiu / Hive-JSON-Serde

Read - Write JSON SerDe for Apache Hive.
Other
733 stars 393 forks source link

parse complex json file failed #81

Closed timeforce closed 7 years ago

timeforce commented 10 years ago

my json file is like: {"lastTimestamp": xxxxxxx, "obj":[{"description":"xxxxx", "timestamp": xxxxxxxx, "prefix":"xxx", "tags":{}, "encoding":"xxxx"}], "sucess":"xxxx", "totalResults":"xxx", "elapsedms":"xxx"}

And I tried:

hive> create table json(lastTimestamp string, obj array<struct<description:string, timestamp:string,prefix:string, encoding:string>>, success string,totalResults string,elapsedms string)

ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe';

But got error:

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Could not initialize class org.openx.data.jsonserde.objectinspector.JsonObjectInspectorFactory

I omitted "tags":{} as I don't know how to deal with it in the schema. Is that the root cause?

Thanks

code-rider commented 10 years ago

hi having same issue

rcongiu commented 10 years ago

So, I tried the code above...a few things.

 create table json_81(
            lastTimestamp string, 
            obj array<struct<
                        description:string, 
                        ts:string,prefix:string,  
                        encoding:string>>, 
            success string,
            totalResults string,
            elapsedms string)
     ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'
WITH SERDEPROPERTIES ( "mapping.ts" = "timestamp" ) ;

see how I replaced 'timestamp' with 'ts' and added the mapping in the serde properties.

hive> select * from json_81;
OK
xxxxxxx [{"description":"xxxxx","ts":"xxxxxxxx","prefix":"xxx","encoding":"xxxx"}]  NULL    xxx xxx
rcongiu commented 7 years ago

Closing as no answer to my observation.