avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Weishung Chung <weish...@gmail.com>
Subject Re: does the map need to be embedded in a record
Date Wed, 13 Apr 2011 17:38:06 GMT
It looks like only the RecordSchema has implemented the getField method
getField(String fieldname)

If I were to use the example schema, (map without embedded in a record),
I can't use the getField method because the MapSchema does not implement the
getField method, so, the following doesn't work

Schema s = Schema.parse(new File(MY_SCHEMA_FILE);
GenericRecord t = new GenericData.Record(s.getField("hi").schema());

So, I am curious how  to create the GenericRecord instance to populate
fields a and b of the record before inserting into the Map?



On Wed, Apr 13, 2011 at 12:16 PM, Scott Carey <scott@richrelevance.com>wrote:

> In general you don't need to wrap an unnamed complex type (map, array,
> union) in a record.
>
> Some language APIs might not support these 'naked' types with the same
> level of ease that they support named ones.
>
> Note in your schema below the "name" field -- "mapping" is completely
> ignored.  Maps don't have names.
>
> Other 'nameless' schemas are ones with a single intrinsic data type, like:
>
> { "type": "int" }
>
>
> On 4/13/11 9:52 AM, "Weishung Chung" <weishung@gmail.com> wrote:
>
> Hello,
>
> I have a question about Avro schema. Does the map type need to be embedded
> in a record? Could I have a schema like this without embedding the map in a
> record?
>
> {
>     "name": "mapping",
>     "type": "map",
>     "values":{
>         "type":"record",
>         "name":"hi",
>         "fields":[
>             {"name":"a","type":"string"},
>             {"name":"b","type":"string"}
>         ]
>     }
> }
>
>
> Thank you
>
>

Mime
View raw message