Only records have fields. Maps have value types: http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getValueType%28%29
Likewise, arrays have http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getElementType%28%29 and unions have http://avro.apache.org/docs/current/api/java/org/apache/avro/Schema.html#getTypes%28%29 On 4/13/11 10:38 AM, "Weishung Chung" <[email protected]<mailto:[email protected]>> wrote: 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 <[email protected]<mailto:[email protected]>> 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" <[email protected]<mailto:[email protected]>> 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
