Thanks.  I'm so happy to see there is an active Avro community.

I've created the schema below and I can parse it without errors.  How
do I create a "User" record object in Java?
If I use "new GenericData.Record(usersSchema)"  I get the "Users"
Record and not the "User" Record?

Thanks,
Curtis




{
 "type": "record",
 "name": "Users",
 "fields": [
    {
     "name": "userArray",
          "type": {
            "type": "array",
            "items": {
              "name": "User",
              "type": "record",
              "fields": [
                    {"name": "name", "type": "string"},
                    {"name": "id", "type": "long"}
                    ]
          }
        }
      }
    ]
   }


On Mon, Mar 21, 2011 at 10:18 AM, Doug Cutting <[email protected]> wrote:
> You can use the schema David provided directly for arrays of the User
> record.  But if you want to have a named type for an array of User then
> you need to define a record with that as a field, e.g., something like:
>
> {"type": "record",
>  "name": "Users",
>  "fields": [
>   "name": "userArray",
>   "type": {
>     "type": "array",
>     "items": {
>       "name": "User",
>       "type": "record",
>       "fields" : [ .... ]
>     }
>   }
>  ]
> }
>
> Doug
>
> On 03/21/2011 09:43 AM, Curtis Jensen wrote:
>> Great.  However, how to use it?
>> I've modified my schema to look like below:
>>
>> In java, when I try to parse this schema with:
>> Schema usersSchema = Schema.parse(USERS_SCHEMA);
>>
>> I get an "org.apache.avro.SchemaParseException: No type" exception
>> (Here USERS_SCHEMA is the schema below).
>>
>>
>> {
>>  "name": "Users",
>>  "type": {
>>  "type": "array",
>>  "items": {
>>        "name": "User",
>>        "type": "record",
>>        "fields" : [
>>                {"name": "name", "type": "string"},
>>                 {"name": "id", "type": "long"}
>>               ]
>>        }
>>    }
>> }
>>
>> On Mon, Mar 21, 2011 at 8:42 AM, David Rosenstrauch <[email protected]> 
>> wrote:
>>> On 03/21/2011 11:28 AM, Curtis Jensen 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
>>>>
>>>>
>>>>  [
>>>>  {
>>>>  "name": "User",
>>>>  "type": "record",
>>>>  "fields": [
>>>>    {"name": "name", "type": "string"},
>>>>    {"name": "id", "type": "int"}]
>>>>  },
>>>>  {
>>>>  "type": "array", "items": "User"
>>>>  }
>>>>  ]}
>>>
>>>
>>> We do it like so:
>>>
>>> "name": "AttributeMappings",
>>> "type": {
>>>        "type": "array",
>>>        "items": {
>>>                "name": "AttributeMapping",
>>>                "type": "record",
>>>                "fields" : [
>>>                        {"name": "Key", "type": "long"},
>>>                        {"name": "Value", "type": "long"}
>>>                ]
>>>        }
>>> }
>>>
>>> HTH,
>>>
>>> DR
>>>
>

Reply via email to