avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Hammerbacher <ham...@cloudera.com>
Subject Re: Avro schema for nested arrays doesn't work
Date Mon, 13 Sep 2010 00:00:02 GMT
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.

Try:

{"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.

Later,
Jeff


On Fri, Sep 10, 2010 at 5:10 PM, Alex Kroifer <alex.kroifer@gmail.com>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.
>

Mime
View raw message