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

Marcos Lopez Gonzalez updated AVRO-2140:
----------------------------------------
    Description: 
When validating a union Schema in the method
{code:java}
Schema.isValidDefault(Schema schema, JsonNode defaultValue){code}
for the case of UNION it only validates the first type of the union: 
{code:java}
case UNION: // union default: first branch
return isValidDefault(schema.getTypes().get(0), defaultValue);
{code}
This leads to some warnings that can create confusion.

For example, if you have a field like this:
{code:java}
{
  "name" : "synonym",
  "type" : [ "null", "boolean" ],
  "default" : false
}
{code}
{{and you assign it false as default you get this warning because it only 
validates that false is not null:}}
{code:java}
[WARNING] Avro: Invalid default for field synonym: false not a 
["null","boolean"]{code}
I think in this cases the validation should check all the types of the union to 
avoid these warnings.

I would be happy to create a PR to improve this if you think we should go for 
it.

 

 

  was:
When validating a union Schema in the method
{code:java}
Schema.isValidDefault(Schema schema, JsonNode defaultValue){code}
for the case of UNION it only validates the first type of the union:

 
{code:java}
case UNION: // union default: first branch
return isValidDefault(schema.getTypes().get(0), defaultValue);
{code}
This leads to some warnings that can create confusion.

 

For example, if you have a field like this:

 
{code:java}
{
  "name" : "synonym",
  "type" : [ "null", "boolean" ],
  "default" : false
}
{code}
{{and you assign it false as default you get this warning because it only 
validates that false is not null:}}
{code:java}
[WARNING] Avro: Invalid default for field synonym: false not a 
["null","boolean"]{code}
 

I think in this cases the validation should check all the types of the union to 
avoid these warnings.

I would be happy to create a PR to improve this if you think we should go for 
it.

 

 


> Validation of Union Schemas
> ---------------------------
>
>                 Key: AVRO-2140
>                 URL: https://issues.apache.org/jira/browse/AVRO-2140
>             Project: Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.8.2
>            Reporter: Marcos Lopez Gonzalez
>            Priority: Minor
>
> When validating a union Schema in the method
> {code:java}
> Schema.isValidDefault(Schema schema, JsonNode defaultValue){code}
> for the case of UNION it only validates the first type of the union: 
> {code:java}
> case UNION: // union default: first branch
> return isValidDefault(schema.getTypes().get(0), defaultValue);
> {code}
> This leads to some warnings that can create confusion.
> For example, if you have a field like this:
> {code:java}
> {
>   "name" : "synonym",
>   "type" : [ "null", "boolean" ],
>   "default" : false
> }
> {code}
> {{and you assign it false as default you get this warning because it only 
> validates that false is not null:}}
> {code:java}
> [WARNING] Avro: Invalid default for field synonym: false not a 
> ["null","boolean"]{code}
> I think in this cases the validation should check all the types of the union 
> to avoid these warnings.
> I would be happy to create a PR to improve this if you think we should go for 
> it.
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to