avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: field union default (in Java)
Date Mon, 16 Aug 2010 19:03:18 GMT
On 08/16/2010 11:34 AM, John Kristian wrote:
> It seems tricky to add a nullable field with a default (for compatibility
> with previous versions).  I find that the type of the default value must be
> declared first in the union.  For example, this works:
>
> {"name":"myField", "type":["int", "null"], "default": 3}
>
> But this doesn't:
>
> {"name":"myField", "type":["null", "int"], "default": 3}
>
> When I resolve the latter from a writer's schema that doesn't declare the
> field, I get the value null, not 3.  There's a similar problem with a null
> default: the resolved value is zero, not null, if "int" comes first in the
> union.

John,

That's the intended, specified behavior:

"Default values for union fields correspond to the first schema in the 
union."

http://avro.apache.org/docs/current/spec.html#schema_complex

Doug

Mime
View raw message