You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by "Bogala, Chandra Reddy" <Ch...@gs.com> on 2014/01/07 12:04:52 UTC

How to generate json/complex object type from hive table

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