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

Alexey Raga commented on AVRO-3671:
-----------------------------------

The bug seems to be even more severe, it looks like generated Avro types with 
unions containing enums do not survive roundtrip!

{*}Example{*}:

A type that has property of type:
{code:java}
["null", "string", "Suit"] {code}
 

 

When the value of this property is set to "Suit", then:
 * It is correctly serialised
 * When deserialised back, the value of that property becomes "int" 
representation of that enum
 * Serialising the deserialised value fails with this error:

{code:java}
Avro.AvroException: Cannot find a match for System.Int32 in 
["null","string",{"type":"enum","name":"Suit" .... {code}
 

Looks like the deserialised value should never be of type "int" when the "real" 
type is "enum" to be working correctly.

> Codegen: int and enum values within Unions are indistinguishable
> ----------------------------------------------------------------
>
>                 Key: AVRO-3671
>                 URL: https://issues.apache.org/jira/browse/AVRO-3671
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: csharp
>    Affects Versions: 1.11.1
>            Reporter: Alexey Raga
>            Priority: Major
>
> When there is a schema that contains an enum:
> {code:java}
> { 
>   "type": "enum", 
>   "name": "Suit", 
>   "symbols": ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"] 
> } {code}
> and a field of this union type (allowed by the specification):
> {code:java}
> "type": [ "null", "int", "Suit" ]{code}
> The C# code generator generates a value of type "object" for this field 
> (union) as a part of ISpecificRecord.
> When deserialising Avro, this field always contains numeric values, even when 
> the value of type "Suit" was set for serialisation.
>  
> There seems to be no way in the client code to figure out whether the value 
> is supposed to be "Suit" or "int". Because the property of type "object" 
> always contains "int" values inside.
>  
> I strongly suspect that the same problem happens when using unions with 
> multiple enum types, which is explicitly allowed by the specification: 
> {noformat}
> > Unions may not contain more than one schema with the same type, except for 
> > the named types record, fixed and enum. 
> > For example, unions containing two array types or two map types are not 
> > permitted, but two types with different 
> > names are permitted. (Names permit efficient resolution when reading and 
> > writing unions.){noformat}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to