[ 
https://issues.apache.org/jira/browse/AVRO-3671?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexey Raga updated AVRO-3671:
------------------------------
    Description: 
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}
 

  was:
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}
 


> 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