You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Davide Altomare (JIRA)" <ji...@apache.org> on 2018/08/03 12:10:00 UTC

[jira] [Commented] (AVRO-1118) Specifying null as default of a union only works if null is specified as first type in the union

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

Davide Altomare commented on AVRO-1118:
---------------------------------------

.

> 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
>            Priority: Major
>
> 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 was sent by Atlassian JIRA
(v7.6.3#76005)