Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Avro >> mail # user >> Builder pattern and default values in records


Copy link to this message
-
Builder pattern and default values in records
Hi,

I was confused about why the Avro compiler wasn't initializing my record's
member variables with the default values I specified in my IDL/schema, and
then I came across this thread which explained the issue:

http://search-hadoop.com/m/iDVTn1JVeSR1

In the above thread Doug made this comment:

"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."

That sounds like a good approach, using mutators to track which fields have
been set.  Records could also implement the builder pattern, which would
make it much more convenient to construct records by chaining setter
invocations.

It looks like there has been some discussion of this in AVRO-726 and
AVRO-770, but there hasn't been much activity lately.  Is anyone actively
working on this?  If no one has the time, I would be glad to work on a
patch.

-James