[
https://issues.apache.org/jira/browse/AVRO-1803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Marcel Silberhorn updated AVRO-1803:
------------------------------------
Description:
as described in
https://avro.apache.org/docs/current/spec.html
{quote}h6. Unions
Unions, as mentioned above, are represented using JSON arrays. For example,
{{\["null", "string"\]}} declares a schema which may be either a null or string.
(Note that when a default value is specified for a record field whose type is a
union, the type of the default value must match the +first+ element of the
union. Thus, for unions containing "null", the "null" is usually listed first,
since the default value of such unions is typically null.){quote}
and the given example for Handshake with
{code}
{"name": "clientProtocol", "type": ["null", "string"]},
{code}
or even the "tweet.hashtags" example from
http://stackoverflow.com/questions/31864450
as seen in http://stackoverflow.com/questions/9417732 you have to explicit
define the {{"default": null}} for the "nullable union field", else you get
{{Field clientProtocol type:UNION pos:0 not set and has no default value}}
so either there is a bug in the documentation or in the code ,)
If its "just" a documentation error, please decrease this bug to a wish: add
some compiler warnings when using union without default value
was:
as described in
https://avro.apache.org/docs/current/spec.html
{quote}h6. Unions
Unions, as mentioned above, are represented using JSON arrays. For example,
{{\["null", "string"\]}} declares a schema which may be either a null or string.
(Note that when a default value is specified for a record field whose type is a
union, the type of the default value must match the +first+ element of the
union. Thus, for unions containing "null", the "null" is usually listed first,
since the default value of such unions is typically null.){quote}
and the given example for Handshake with
{code}
{"name": "clientProtocol", "type": ["null", "string"]},
{code}
or even the "tweet.hashtags" example from
http://stackoverflow.com/questions/31864450
as seen in http://stackoverflow.com/questions/9417732 you have to explicit
define the {{"default": null}} for the "nullable union field", else you get
{{Field clientProtocol type:UNION pos:0 not set and has no default value}}
so either there is a bug in the documentation or in the code ,)
> nullable fields and it's default value
> --------------------------------------
>
> Key: AVRO-1803
> URL: https://issues.apache.org/jira/browse/AVRO-1803
> Project: Avro
> Issue Type: Bug
> Components: build
> Affects Versions: 1.7.7, 1.8.0
> Reporter: Marcel Silberhorn
> Priority: Minor
>
> as described in
> https://avro.apache.org/docs/current/spec.html
> {quote}h6. Unions
> Unions, as mentioned above, are represented using JSON arrays. For example,
> {{\["null", "string"\]}} declares a schema which may be either a null or
> string.
> (Note that when a default value is specified for a record field whose type is
> a union, the type of the default value must match the +first+ element of the
> union. Thus, for unions containing "null", the "null" is usually listed
> first, since the default value of such unions is typically null.){quote}
> and the given example for Handshake with
> {code}
> {"name": "clientProtocol", "type": ["null", "string"]},
> {code}
> or even the "tweet.hashtags" example from
> http://stackoverflow.com/questions/31864450
> as seen in http://stackoverflow.com/questions/9417732 you have to explicit
> define the {{"default": null}} for the "nullable union field", else you get
> {{Field clientProtocol type:UNION pos:0 not set and has no default value}}
> so either there is a bug in the documentation or in the code ,)
> If its "just" a documentation error, please decrease this bug to a wish: add
> some compiler warnings when using union without default value
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)