avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Carey <sc...@richrelevance.com>
Subject Re: record containing array of records in python-avro
Date Fri, 11 Feb 2011 18:08:12 GMT
Yes, that is a common mistake.  Try:

{"type":"record","name":"outer","fields":[{"name":"a","type":{"type":"array
","items":"string"}}]}



The problem is that "a" is a field, and the field's name is "a".  Arrays
don't have names, they are a nameless type.  Therefore, without the
nesting the "items" part applies to the field, not the array, but it is an
array property.

Another way to think about it is that "string" is shorthand for
{"type":"string"}.  Likewise, if you declare and name a record, you can
simply reference its name after "type": afterwards.  "string" is a
built-in name.

If there is a bug here, it is that the error message is not that clear to
someone new with Avro.

In Java, this error now has the message:

org.apache.avro.SchemaParseException: "array" is not a defined name. The
type of the "a" field must be a defined name or a {"type": ...} expression.

-Scott

On 2/11/11 8:59 AM, "Christopher Armstrong"
<chris.armstrong@idsoftware.com> wrote:

>On 02/10/2011 07:25 PM, Christopher Armstrong wrote:
>> Hi guys. I'm having trouble declaring a record with an array of
>> records in Python.
>
>Actually, this is a red herring. The problem is much simpler: I can't
>have a record that contains an array as a field. Is this possible?
>
>
>>>>  parse('{"name": "outer", "type": "record", "fields": [{"name": "a",
>>>>"type": "array", "items": "string"}]}')
>array a False None None<avro.schema.Names object at 0x7f7f8acbb490>
>Traceback (most recent call last):
>   File "<stdin>", line 1, in<module>
>   File "/home/radix/lib/python/avro-1.4.1-py2.6.egg/avro/schema.py",
>line 709, in parse
>     return make_avsc_object(json_data, names)
>   File "/home/radix/lib/python/avro-1.4.1-py2.6.egg/avro/schema.py",
>line 665, in make_avsc_object
>     return RecordSchema(name, namespace, fields, names, type)
>   File "/home/radix/lib/python/avro-1.4.1-py2.6.egg/avro/schema.py",
>line 601, in __init__
>     field_objects = RecordSchema.make_field_objects(fields, names)
>   File "/home/radix/lib/python/avro-1.4.1-py2.6.egg/avro/schema.py",
>line 569, in make_field_objects
>     new_field = Field(type, name, has_default, default, order, names)
>   File "/home/radix/lib/python/avro-1.4.1-py2.6.egg/avro/schema.py",
>line 311, in __init__
>     raise SchemaParseException(fail_msg)
>avro.schema.SchemaParseException: Type property "array" not a valid Avro
>schema: Could not make an Avro Schema object from array.
>
>
>
>
>-- 
>Christopher Armstrong, id Software
>


Mime
View raw message