You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Matthieu Monsch (JIRA)" <ji...@apache.org> on 2016/06/10 02:28:21 UTC

[jira] [Comment Edited] (AVRO-1340) use default to allow old readers to specify default enum value when encountering new enum symbols

    [ https://issues.apache.org/jira/browse/AVRO-1340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15323752#comment-15323752 ] 

Matthieu Monsch edited comment on AVRO-1340 at 6/10/16 2:27 AM:
----------------------------------------------------------------

Zoltan's suggestion makes sense.

Alternatively we could allow each enum symbol to optionally declare another symbol to use if the original doesn’t exist in the reader’s schema (resolution could be transitive). It’s slightly more flexible since it allows aliasing to be done per symbol and defined when the new symbol is added (rather than when the union is initially created). A downside is that it can be more verbose.

The JSON schema could look something like:

{code:javascript}
{
  “type”: “enum”,
  “name”: “Suit”,
  “symbols”: [“UNKNOWN”, "CLUBS", "HEARTS", “SPADES”, “DIAMONDS”],
  “symbolAliases”: {
    “DIAMONDS”: “UNKNOWN”,
    “SPADES”: “UNKNOWN"
  }
}
{code}

And the IDL:

{code:java}
enum Suit {
  UNKNOWN,
  CLUBS,
  HEARTS,
  SPADES ? UNKNOWN,
  DIAMONDS ? UNKNOWN
}
{code}


was (Author: mtth):
Zoltan's suggestion makes sense.

Alternatively we could allow each enum symbol to optionally declare another symbol to use if the original doesn’t exist in the reader’s schema (resolution could be transitive). It’s slightly more flexible since it allows aliasing to be done per symbol and defined when the new symbol is added (rather than when the union is initially created). A downside is that it can be more verbose.

The JSON schema could look something like:

{code:json}
{
  “type”: “enum”,
  “name”: “Suit”,
  “symbols”: [“UNKNOWN”, "CLUBS", "HEARTS", “SPADES”, “DIAMONDS”],
  “symbolAliases”: {
    “DIAMONDS”: “UNKNOWN”,
    “SPADES”: “UNKNOWN"
  }
}
{code}

And the IDL:

{code:java}
enum Suit {
  UNKNOWN,
  CLUBS,
  HEARTS,
  SPADES ? UNKNOWN,
  DIAMONDS ? UNKNOWN
}
{code}

> use default to allow old readers to specify default enum value when encountering new enum symbols
> -------------------------------------------------------------------------------------------------
>
>                 Key: AVRO-1340
>                 URL: https://issues.apache.org/jira/browse/AVRO-1340
>             Project: Avro
>          Issue Type: Improvement
>          Components: spec
>         Environment: N/A
>            Reporter: Jim Donofrio
>            Priority: Minor
>
> 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.
> This makes it difficult to use enum's because you can never add a enum value and keep old reader's compatible. Why not use the default option to refer to one of enum values so that when a old reader encounters a enum ordinal it does not recognize, it can default to the optional schema provided one. If the old schema does not provide a default then the older reader can continue to fail as it does today.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)