You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Michael Artz <mi...@redjack.com> on 2011/03/23 03:52:18 UTC

Recursively nested arrays

Is there a way to structure a schema to support recursively nested arrays, i.e. an arbitrary number of arrays within arrays?  As I haven't found a way to reference an array/items "type" by name, I'm not sure that its possible.  Anyone know any better?

Thanks,
-Mike

Re: Recursively nested arrays

Posted by Scott Carey <sc...@richrelevance.com>.
Note that wrapping records does not increase serialization size.  They may
require special handling to have the most compact in-memory representation
depending on the API in use.

On 3/23/11 6:34 AM, "Douglas Creager" <dc...@dcreager.net> wrote:

>> Is there a way to structure a schema to support recursively nested
>>arrays, i.e. an arbitrary number of arrays within arrays?  As I haven't
>>found a way to reference an array/items "type" by name, I'm not sure
>>that its possible.  Anyone know any better?
>
>You need a wrapper record, to give you something that you can name:
>
>{
>  "type": "record",
>  "name": "foo",
>  "fields": [
>    { "name": "contents", "type": { "type": "array", "items": "foo" } }
>  ]
>}
>
>In general, you always need a record if you want a recursive type, since
>records are the only things that both (a) have names, and (b) can contain
>subschemas.
>
>­doug


Re: Recursively nested arrays

Posted by Douglas Creager <dc...@dcreager.net>.
> Is there a way to structure a schema to support recursively nested arrays, i.e. an arbitrary number of arrays within arrays?  As I haven't found a way to reference an array/items "type" by name, I'm not sure that its possible.  Anyone know any better?

You need a wrapper record, to give you something that you can name:

{
  "type": "record",
  "name": "foo",
  "fields": [
    { "name": "contents", "type": { "type": "array", "items": "foo" } }
  ]
}

In general, you always need a record if you want a recursive type, since records are the only things that both (a) have names, and (b) can contain subschemas.

–doug