You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by David Rosenstrauch <da...@darose.net> on 2010/07/12 21:39:59 UTC

Declaring array item types inline

Is it possible to declare array item types inline?  i.e., instead of this:

[
   {
     "type": "record",
     "name": "SubRecord",
     "fields" : [
       {"name": "field1", "type": "int"},
       {"name": "field2", "type": "int"}
     ]
   },
   {
     "type": "record",
     "name": "TestRecord",
     "fields" : [
       {
         "name": "SubRecords",
         "type": {
           "type": "array",
           "items": "SubRecord"
         }
       }
     ]
   }
]

Would it be possible to do something like this:

{
   "type": "record",
   "name": "TestRecord",
   "fields" : [
     {
       "name": "SubRecords",
       "type": {
         "type": "array",
         "items": {
           "type": "record",
           "name": "SubRecord",
           "fields" : [
             {"name": "field1", "type": "int"},
             {"name": "field2", "type": "int"}
           ]
         }
       }
     }
   ]
}

It's quite a bit more clunky to do the former.

Thanks,

DR

Re: Declaring array item types inline

Posted by David Rosenstrauch <da...@darose.net>.
Yes, apparently so.  I was getting a different parse error, and thought 
this was disallowed.

Sorry for the noise.

DR

On 07/12/2010 04:59 PM, Scott Carey wrote:
> Yes, you can declare types as they are encountered.
>
>
> On Jul 12, 2010, at 12:39 PM, David Rosenstrauch wrote:
>
>> Is it possible to declare array item types inline?  i.e., instead of this:
>>
>> [
>>    {
>>      "type": "record",
>>      "name": "SubRecord",
>>      "fields" : [
>>        {"name": "field1", "type": "int"},
>>        {"name": "field2", "type": "int"}
>>      ]
>>    },
>>    {
>>      "type": "record",
>>      "name": "TestRecord",
>>      "fields" : [
>>        {
>>          "name": "SubRecords",
>>          "type": {
>>            "type": "array",
>>            "items": "SubRecord"
>>          }
>>        }
>>      ]
>>    }
>> ]
>>
>> Would it be possible to do something like this:
>>
>> {
>>    "type": "record",
>>    "name": "TestRecord",
>>    "fields" : [
>>      {
>>        "name": "SubRecords",
>>        "type": {
>>          "type": "array",
>>          "items": {
>>            "type": "record",
>>            "name": "SubRecord",
>>            "fields" : [
>>              {"name": "field1", "type": "int"},
>>              {"name": "field2", "type": "int"}
>>            ]
>>          }
>>        }
>>      }
>>    ]
>> }
>>
>> It's quite a bit more clunky to do the former.
>>
>> Thanks,
>>
>> DR
>


Re: Declaring array item types inline

Posted by Scott Carey <sc...@richrelevance.com>.
Yes, you can declare types as they are encountered.


On Jul 12, 2010, at 12:39 PM, David Rosenstrauch wrote:

> Is it possible to declare array item types inline?  i.e., instead of this:
> 
> [
>   {
>     "type": "record",
>     "name": "SubRecord",
>     "fields" : [
>       {"name": "field1", "type": "int"},
>       {"name": "field2", "type": "int"}
>     ]
>   },
>   {
>     "type": "record",
>     "name": "TestRecord",
>     "fields" : [
>       {
>         "name": "SubRecords",
>         "type": {
>           "type": "array",
>           "items": "SubRecord"
>         }
>       }
>     ]
>   }
> ]
> 
> Would it be possible to do something like this:
> 
> {
>   "type": "record",
>   "name": "TestRecord",
>   "fields" : [
>     {
>       "name": "SubRecords",
>       "type": {
>         "type": "array",
>         "items": {
>           "type": "record",
>           "name": "SubRecord",
>           "fields" : [
>             {"name": "field1", "type": "int"},
>             {"name": "field2", "type": "int"}
>           ]
>         }
>       }
>     }
>   ]
> }
> 
> It's quite a bit more clunky to do the former.
> 
> Thanks,
> 
> DR