hive-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bogala, Chandra Reddy" <Chandra.Bog...@gs.com>
Subject How to generate json/complex object type from hive table
Date Tue, 07 Jan 2014 11:04:52 GMT
Hi,
How to generate json data from a table data that's in hive? For example, if I have data in
table format (below) and want to generate data in json format  below.
I want to group by person name and fill the STRUCT and ARRAY with that person. So finally
I should get one row per person. I tried with NAMED_STRUCT('NAME', NAME,' AREA', AREA) etc
. Struct object filled with only one entry, Sogetting multiple rows per person .I need just
one row per person with all embed data.

Name

CITY.Name

City.AREA

Child.Name

Rok

Grosuplje

12544

Matej-1

Rok

Grosuplje

12544

Matej-2

Rok

Grosuplje

12544

Matej-3

Simon

Spodnji Breg

362.2354

Simonca-1

Simon

Spodnji Breg

362.2354

Simonca-2

Simon

Spodnji Breg

362.2354

Simonca-3

Simon

Spodnji Breg

362.2354

Simonca-4



Create table person (
                Name String,
               CITY:STRUCT<NAME:STRING,AREA:STRING>,
              CHILDREN ARRAY<NAME:STRING>)

           STORED BY 'com.mongodb.hadoop.hive.MongoStorageHandler'

         WITH SERDEPROPERTIES('mongo.columns.mapping'='<blah>,<blah>.....')

         TBLPROPERTIES('mongo.uri'='mongodb://localhost:27017/test.persons')




{ "name":"Rok", "city":{"name":"Grosuplje", "area":12544}, "children":[{"name":"Matej"}]}
{ "name":"Melanija", "children":[]}
{ "name":"Simon", "city":{"name":"Spodnji Breg", "area":362.2354}, "children":[{"name":"Simonca"},{"name

Thanks,
Chandra

Mime
View raw message