hive query creation for nested fields

23 views
Skip to first unread message

balaji rajan

unread,
Jul 28, 2017, 6:16:06 AM7/28/17
to Hands On Hadoop, Hive, Pig Training
Hell guys,

I am trying to add hive schema  to query data from hdfs file system which has a parent field, sub field and sub of sub field.

My data format is:
++++
country -> main fields
state -> sub field of main field "country"
city -> sub field of field "state"
+++++

Hive schema:
+++++
    CREATE EXTERNAL TABLE IF NOT EXISTS test_table (
    country map<string,map<string,string>>

    )
    PARTITIONED BY (date string, hour string) 
    ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' 
    STORED AS TEXTFILE LOCATION '/user/logs/';
++++

I could query country['state'] and country['city'] from the above table but not able query the parent field "country". If change the schema to  country map<string,string>. it works  for country and country['state'] works but not for country['start']['city'].


Can anyone help me figure out the way to query all three fields(parent, child and child of child) ?


Message has been deleted

swa...@sevenmentor.com

unread,
Dec 6, 2017, 12:13:44 AM12/6/17
to Hands On Hadoop, Hive, Pig Training
Go for following query,
create external table tblname(schema) 
row format delimited
fields terminated by ','
location '/usr/dirname';


Best Regards,

Swaroop Pachpol
Reply all
Reply to author
Forward
0 new messages