quux00 / hive-json-schema

Tool to generate a Hive schema from a JSON example doc
229 stars 70 forks source link

Hive creation failed #5

Open rpushpa opened 9 years ago

rpushpa commented 9 years ago

Hi, This was so great tool for simplifing the json record into hive structure. I have created the jar files and used them to generate hive DDL . But the create table statement is failing in hive. can you pls help to resolve the issue?

sample data record: {"country":"uk","state":"ny","city":"fr","street":"nyk","zip":"1009","data":[{"country_code":"uk","state_set":"ny","city_code":"fr","street_code":"nyk","zip_code":"1009"}]}

user@ubuntu:~/lab/programs$ java -jar json-hive-schema-1.0-jar-with-dependencies.jar /home/user/Documents/json_cntry_schema.json CREATE TABLE x ( city string, country string, data array<struct<city_code:string, country_code:string, state_set:string, street_code:string, zip_code:string>>, state string, street string, zip string) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe';

hive> CREATE external TABLE jcountry (

city string, country string, data array<struct<city_code:string, country_code:string, state_set:string, street_code:string, zip_code:string>>, state string, street string, zip string) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' LOCATION '/user/data1/jason/'; FAILED: Parse Error: line 4:2 mismatched input 'data' expecting Identifier near ',' in column specification

Thanks , Pushpa

mtoupsUNO commented 9 years ago

This line is wrong:

data array>,

In other words, an array of what?

It looks like your sample is actually an array containing a struct, so maybe something like:

data array<struct<country_code:string, state_set:string, ... >>,

I'll let you finish writing out the struct, but that's the idea.

rpushpa commented 9 years ago

Thanks. I have tried same as array having struct data type and given the DDL as shown above. Still I am failing in creating the table . More information ::My hive version is hive 0.9 version

mtoupsUNO commented 9 years ago

Please provide the CREATE statement you used which is not working.

rpushpa commented 9 years ago

Here is the create table statement i used: CREATE external TABLE jcountry ( city string, country string, data array <struct<city_code:string, country_code:string, state_set:string, street_code:string, zip_code:string>>, state string, street string, zip string) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' LOCATION '/user/data1/jason/';

rpushpa commented 9 years ago

Hi.. Just wanted to check if you need any aditional information on resolving the issue

mtoupsUNO commented 9 years ago

Are you still getting a parse error? If so, what line number? Provide the whole error message here.

rpushpa commented 9 years ago

Yes I get same erro telling the same for issue:

FAILED: Parse Error: line 4:2 mismatched input 'data' expecting Identifier near ',' in column specification

Thanks , Pushpa

mtoupsUNO commented 9 years ago

Oh, data could be a reserved keyword. Try wrapping it in backticks, i.e.

`data` array<struct<...>>
telebh commented 2 years ago

I am trying to generate jar files using "mvn package" but it always freezes as follows. Please can you advise?

[INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for net.thornydev:json-hive-schema:jar:1.0 [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 13, column 15 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] [INFO] -------------------< net.thornydev:json-hive-schema >------------------- [INFO] Building json-hive-schema 1.0 [INFO] --------------------------------[ jar ]--------------------------------- Downloading from nexus: http://nexus.elsst.com/content/groups/public/org/apache/maven/plugins/maven-assembly-plugin/2.4/maven-assembly-plugin-2.4.jar Progress (1): 25/226 kB