avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: Default values not supported in the client write?
Date Mon, 02 Aug 2010 17:53:36 GMT
On 08/02/2010 09:51 AM, Tim Robertson wrote:
> http://www.mail-archive.com/avro-dev@hadoop.apache.org/msg04063.html
> tells me that defaults aren't used at write time, but it means that I
> have to initiate all the Strings with "=new Utf8();" each time I
> create a message payload - is this correct?

Defaults must used at read time.  This is is a requirement.  But that 
doesn't mean they cannot be used elsewhere, as a feature of a particular 
implementation.

> I wonder the reasoning behind not initializing with null types (e.g.
> for String using new Utf8()) in the client generation.

There's a performance concern, since if user code subsequently sets the 
value, then the 'new Utf8("")' from the default value would still be 
executed.  Using constants for default values could fix that, but, since 
values are reused, constants are not safe.

> It means I
> either need to modify the generated sources, or wrap them in some kind
> of factory/builder right?  Is that a common practice for avro or are
> others doing something different?

Factory/builders are probably the best approach at present.  Ideally we 
might generate accessor methods, track which fields have been set, and 
then set unset fields to their default values before writing.

Doug

Mime
View raw message