Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Avro >> mail # user >> Avro schema for nested arrays doesn't work

Copy link to this message
Re: Avro schema for nested arrays doesn't work
Hey Alex,

Inside the "fields" attribute of the "Rec1" record, you can't say "type":
"array"; you need to 1) give the field a name and 2) make "type" be a valid
avro schema, not a valid avro type.


{"type": "array", "items": {"name": "Rec1", "type": "record", "fields" : [
       {"name": "Array1", "type": {"type": "array", "items": {"name":
"Rec2", "type":"record", "fields" : [
                   {"name": "Scalar", "type": "string"}]}}}]}}

I'd also recommend trying out Avro IDL; it makes writing schemas and
protocols much more pleasant.

On Fri, Sep 10, 2010 at 5:10 PM, Alex Kroifer <[EMAIL PROTECTED]>wrote:

> Avro schema for nested arrays definition doesn't parse:
> Schema:
> {"type": "array", "items": {"name": "Rec1", "type": "record", "fields" : [
>        {"type": "array", "items": {"name": "Rec2", "type":"record",
> "fields" : [
>                    {"name": "Scalar", "type": "string"}]}}]}}
> Result:
> No field name:
> {"type":"array","items":{"name":"Rec2","type":"record","fields":[{"name":"Scalar","type":"string"}]}}
> org.apache.avro.SchemaParseException: No field name:
> {"type":"array","items":{"name":"Rec2","type":"record","fields":[{"name":"Scalar","type":"string"}]}}
>         at org.apache.avro.Schema.getRequiredText(Schema.java:981)
>         at org.apache.avro.Schema.parse(Schema.java:907)
>         at org.apache.avro.Schema.parse(Schema.java:934)
>         at org.apache.avro.Schema.parse(Schema.java:813)
> What's wrong?
> Thank you in advance,
> Alex.