Hi Nanda,
If you are in a java environment you can test this and similar scenarios in a
JUnit test using the Schema.Parser object. Here's an example:
@Test
public void testNestedRecordFromString() {
String json = "{\"type\" : \"record\",\"name\": \"TYPE_A\",\"fields\" :
"
+ "[{\"name\": \"one\", \"type\": {\"type\": \"record\",
\"name\": \"TYPE_B\",\"fields\" : "
+ "[ {\"name\" : \"inside_one\",\"type\" : \"string\"}]}}]}";
Schema schema = new Schema.Parser().parse(json);
assertTrue(schema.getFields().get(0).schema().getFields().get(0).name().equalsIgnoreCase("inside_one"));
}
This should be OK in avro (the test above is positive for me), but will not
work with the Avro storage package for pig (see the limitations described here:
https://cwiki.apache.org/confluence/display/PIG/AvroStorage).
Andrew
>________________________________
> From: nanda <[email protected]>
>To: [email protected]
>Sent: Monday, December 5, 2011 12:45 PM
>Subject: Records inside records
>
>Hi,
>
>Is it possible to generate following kind of data object:
>
>{
>'type' : 'record',
>'name': 'TYPE_A',
>'fields' : [
> {'name': 'one', 'type': {'type': 'record', 'name': 'TYPE_B',
>'fields' : [ {'name' : 'inside_one',
> 'type' : 'string}
> ]
> }}
> ]
>}
>
>----------------------------------------------------------------------------------------------------
>Basically my requirement is to send timely updates from server to
>clients(in various language), which might look something like(Dynamic
>Map):
>
>{'field_1' : value_1_type_int,
>'field_2' : value_2_type_string,
>'field_3' : {'field_4' : value_4_long, 'field_5' : {another map..}}
>}
>Why I am inclined to use avro is because I never know in advance what is
>the message structure of an update going to be, it can be any number of
>fields with any amount of nestedness.
>'Record' seems to be a viable option here, but not sure how I can use
>nested structure here.
>Could someone please help here.
>
>Thanks,
>Gaurav Nanda
>
>
>
>
>