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

ASF GitHub Bot commented on AVRO-1340:
--------------------------------------

BirdHowl commented on issue #298: AVRO-1340: Added Enum Defaults and unit tests.
URL: https://github.com/apache/avro/pull/298#issuecomment-382476911
 
 
   >  We could add an `@default` annotation now, or commit this now and add 
that later, I don't have a strong feeling.
   
   I think there's some misunderstanding here - `@default` already works, since 
IDL lets _any_ JSON property be set through annotations (although that behavior 
isn't well-documented). Anything that doesn't work as an annotation doesn't 
work because of being a reserved property. `default`, however is a reserved 
property only for fields.
   
   If I take this a protocol file named `test.avdl`:
   ```
   protocol Test {
     @default("UNKNOWN")
     enum Status {
         SUCCESS,
         FAILURE,
         UNKNOWN
     }
   }
   ```
   
   And then run `avro-tools.jar idl test.avdl` (tested on both this branch and 
`master`), I get this output:
   ```
   {
     "protocol" : "Test",
     "namespace" : null,
     "types" : [ {
       "type" : "enum",
       "name" : "Status",
       "symbols" : [ "SUCCESS", "FAILURE", "UNKNOWN" ],
       "default" : "UNKNOWN"
     } ],
     "messages" : { }
   }
   ```
   
   In my JIRA post, I was attempting to provide reasonable answers to the 
question: "how should we handle cases when both `@default` and the new `=` 
syntax are present."
   
   (Currently on this branch, if I use both I get JSON like:
   
   ```
   {
     "protocol" : "Test",
     "namespace" : null,
     "types" : [ {
       "type" : "enum",
       "name" : "Status",
       "symbols" : [ "SUCCESS", "FAILURE", "UNKNOWN" ],
       "default" : "FAILURE",
       "default" : "UNKOWN"
     } ],
     "messages" : { }
   }
   ```
   )

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> 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
(v7.6.3#76005)

Reply via email to