avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curtis Jensen <cur...@the-jensens.org>
Subject Re: Schema for array of records
Date Mon, 21 Mar 2011 17:47:09 GMT
In one of my iterations of trying to get this to work, I tried the
straight array schema you suggested.  However, in Java, how do I
create a "User" record?  After parsing the schema, the only schema
object I can create from it is an Array object.  How do I populate the
array?

Thanks,
Curtis


On Mon, Mar 21, 2011 at 10:28 AM, Scott Carey <scott@richrelevance.com> wrote:
>
>
> On 3/21/11 8:28 AM, "Curtis Jensen" <curtis@the-jensens.org> wrote:
>
>>How does one create a schema for an array of records?
>>
>>For example, I have a record schema for a user (name and id; see
>>below).  I would like to serialize an array of users.  I've tried
>>various combinations of things, and I'm not getting it to work.
>>
>>Thanks,
>>Curtis
>>
>
> The below Schema is a UNION of "User" and an array of "User". (I' am
> ignoring the trailing unmatched "}")
>
>
>>
>> [
>> {
>> "name": "User",
>> "type": "record",
>> "fields": [
>>   {"name": "name", "type": "string"},
>>   {"name": "id", "type": "int"}]
>> },
>> {
>> "type": "array", "items": "User"
>> }
>> ]}
>
> If you want only an array of Users, do:
>
> {
>  "type": "array", "items": {
>    "name": "User",
>    "type": "record",
>    "fields": [
>      {"name": "name", "type": "string"},
>      {"name": "id", "type": "int"}
>    ]
>  }
> }
>
>
>
> If you want the array to be a field inside of a "Users" record, do:
> {
>  "type": "record", "name":"Users", "fields": [
>  "name": "users", "type":
>    {"type": "array", "items": {
>      "name": "User",
>      "type": "record",
>      "fields": [
>        {"name": "name", "type": "string"},
>        {"name": "id", "type": "int"}
>      ]
>    }
>  ]
> }
>
>
>
> Note, that all fields have a name and type; and a fields type is either
> declared by nesting in { } or with an already defined name.  Arrays do not
> have names, so they cannot be referenced with one.
>
>
>

Mime
View raw message