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

Mike Percy commented on AVRO-1118:
----------------------------------

Note that this occurs when trying to read GenericRecords via DataFileReader 
when the field is not present in the data.
                
> Specifying null as default of a union only works if null is specified as 
> first type in the union
> ------------------------------------------------------------------------------------------------
>
>                 Key: AVRO-1118
>                 URL: https://issues.apache.org/jira/browse/AVRO-1118
>             Project: Avro
>          Issue Type: Bug
>    Affects Versions: 1.6.3
>            Reporter: Mike Percy
>
> There is some unexpected behavior I am coming across where if I specify a 
> union as such:
> "type": ["string", "null"],
> "default": null
> I get an Exception:
> Exception in thread "main" org.apache.avro.AvroTypeException: Non-string 
> default value for string: null
>       at 
> org.apache.avro.io.parsing.ResolvingGrammarGenerator.encode(ResolvingGrammarGenerator.java:363)
>       at 
> org.apache.avro.io.parsing.ResolvingGrammarGenerator.encode(ResolvingGrammarGenerator.java:350)
>       at 
> org.apache.avro.io.parsing.ResolvingGrammarGenerator.getBinary(ResolvingGrammarGenerator.java:293)
>       at 
> org.apache.avro.io.parsing.ResolvingGrammarGenerator.resolveRecords(ResolvingGrammarGenerator.java:271)
>       at 
> org.apache.avro.io.parsing.ResolvingGrammarGenerator.generate(ResolvingGrammarGenerator.java:118)
>       at 
> org.apache.avro.io.parsing.ResolvingGrammarGenerator.generate(ResolvingGrammarGenerator.java:50)
>       at org.apache.avro.io.ResolvingDecoder.resolve(ResolvingDecoder.java:82)
>       at org.apache.avro.io.ResolvingDecoder.<init>(ResolvingDecoder.java:46)
>       at 
> org.apache.avro.io.DecoderFactory.resolvingDecoder(DecoderFactory.java:307)
>       at 
> org.apache.avro.generic.GenericDatumReader.getResolver(GenericDatumReader.java:118)
>       at 
> org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:133)
>       at org.apache.avro.file.DataFileStream.next(DataFileStream.java:233)
>       at org.apache.avro.file.DataFileStream.next(DataFileStream.java:220)
> ...
> Whereas if I specify the schema as:
> "type": ["null", "string"],
> "default": null
> It works as expected.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to