You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Jim Donofrio <do...@gmail.com> on 2013/05/23 16:51:28 UTC

why isnt there an option for a default enum so that the writer can add new enum symbols

The schema resolution page says:

 > if both are enums:
 > if the writer's symbol is not present in the reader's enum, then an 
error is signalled.

Is there a reason you could not allow us to provide one of the symbols 
as a default in the reader so that when the reader read the enum with 
symbol it didnt have, that new symbol would get defaulted to the default 
symbol we provide?

For example with the below schema's this would currently fail if the old 
reader encountered a Enum1.C in the data. Why not provide users the 
option to set "default": "A" for example so that any unknown enum's are 
bined into one? The user might have an unknown enum or something. 
Currently I was going to implement this in my application by just using 
an int type and looking up the ordinal of my own Java Enum. If the int 
is larger than any of the oridinals, the enum would be set to my own 
default value in the enum.

Thanks.

Original schema:

{
     "type": "record",
     "name": "EnumExample",
     "fields": [
         {
             "name": "enum1",
             "type": {
                 "type": "enum",
                 "name": "Enum1",
                 "symbols": ["A", "B"]
             }
         }
     ]
}

New schema:

{
     "type": "record",
     "name": "EnumExample",
     "fields": [
         {
             "name": "enum1",
             "type": {
                 "type": "enum",
                 "name": "Enum1",
                 "symbols": ["A", "B", "C"]
             }
         }
     ]
}


Re: why isnt there an option for a default enum so that the writer can add new enum symbols

Posted by Jim Donofrio <do...@gmail.com>.
I created AVRO-1340

On 05/23/2013 02:49 PM, Scott Carey wrote:
> I think this is simply a feature that has not been added.  It appears at
> quick glance to be a compatible specification change (it does not break
> old code or change the binary format).
>
> Please open a JIRA ticket explaining the use case and we can continue
> discussion there.
>
> On 5/23/13 7:51 AM, "Jim Donofrio" <do...@gmail.com> wrote:
>
>> The schema resolution page says:
>>
>>> if both are enums:
>>> if the writer's symbol is not present in the reader's enum, then an
>> error is signalled.
>>
>> Is there a reason you could not allow us to provide one of the symbols
>> as a default in the reader so that when the reader read the enum with
>> symbol it didnt have, that new symbol would get defaulted to the default
>> symbol we provide?
>>
>> For example with the below schema's this would currently fail if the old
>> reader encountered a Enum1.C in the data. Why not provide users the
>> option to set "default": "A" for example so that any unknown enum's are
>> bined into one? The user might have an unknown enum or something.
>> Currently I was going to implement this in my application by just using
>> an int type and looking up the ordinal of my own Java Enum. If the int
>> is larger than any of the oridinals, the enum would be set to my own
>> default value in the enum.
>>
>> Thanks.
>>
>> Original schema:
>>
>> {
>>      "type": "record",
>>      "name": "EnumExample",
>>      "fields": [
>>          {
>>              "name": "enum1",
>>              "type": {
>>                  "type": "enum",
>>                  "name": "Enum1",
>>                  "symbols": ["A", "B"]
>>              }
>>          }
>>      ]
>> }
>>
>> New schema:
>>
>> {
>>      "type": "record",
>>      "name": "EnumExample",
>>      "fields": [
>>          {
>>              "name": "enum1",
>>              "type": {
>>                  "type": "enum",
>>                  "name": "Enum1",
>>                  "symbols": ["A", "B", "C"]
>>              }
>>          }
>>      ]
>> }
>>
>
>


Re: why isnt there an option for a default enum so that the writer can add new enum symbols

Posted by Scott Carey <sc...@apache.org>.
I think this is simply a feature that has not been added.  It appears at
quick glance to be a compatible specification change (it does not break
old code or change the binary format).

Please open a JIRA ticket explaining the use case and we can continue
discussion there.

On 5/23/13 7:51 AM, "Jim Donofrio" <do...@gmail.com> wrote:

>The schema resolution page says:
>
> > if both are enums:
> > if the writer's symbol is not present in the reader's enum, then an
>error is signalled.
>
>Is there a reason you could not allow us to provide one of the symbols
>as a default in the reader so that when the reader read the enum with
>symbol it didnt have, that new symbol would get defaulted to the default
>symbol we provide?
>
>For example with the below schema's this would currently fail if the old
>reader encountered a Enum1.C in the data. Why not provide users the
>option to set "default": "A" for example so that any unknown enum's are
>bined into one? The user might have an unknown enum or something.
>Currently I was going to implement this in my application by just using
>an int type and looking up the ordinal of my own Java Enum. If the int
>is larger than any of the oridinals, the enum would be set to my own
>default value in the enum.
>
>Thanks.
>
>Original schema:
>
>{
>     "type": "record",
>     "name": "EnumExample",
>     "fields": [
>         {
>             "name": "enum1",
>             "type": {
>                 "type": "enum",
>                 "name": "Enum1",
>                 "symbols": ["A", "B"]
>             }
>         }
>     ]
>}
>
>New schema:
>
>{
>     "type": "record",
>     "name": "EnumExample",
>     "fields": [
>         {
>             "name": "enum1",
>             "type": {
>                 "type": "enum",
>                 "name": "Enum1",
>                 "symbols": ["A", "B", "C"]
>             }
>         }
>     ]
>}
>