avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lewis John Mcgibbney <lewis.mcgibb...@gmail.com>
Subject Re: default write value in schema?
Date Wed, 19 Feb 2014 23:44:04 GMT
+1 we do this in Gora.
Please note that there are some overheads with using the builders...
"namely Avro objects can be created either by invoking a constructor
directly or by using a builder. Unlike constructors, builders will
automatically set any default values specified in the schema. Additionally,
builders validate the data as it set, whereas objects constructed directly
will not cause an error until the object is serialized. However, using
constructors directly generally offers better performance, as builders
create a copy of the datastructure before it is written."

Please see


On Wed, Feb 19, 2014 at 5:39 PM, Christophe Taton <taton@wibidata.com>wrote:

> Hi,
> I'd suggest using the record builders to construct your records: record
> builders will initialize fields with their default values if you don't set
> them.
> C.
> On Wed, Feb 19, 2014 at 9:07 AM, Gary Steelman <gary.steelman42@gmail.com>wrote:
>> Hey Wai,
>> Good question. I've had that problem recently too. My solution has been
>> to set the missing field to a known default value in my code before I try
>> to serialize an object. That is, if some integer is required by the schema,
>> I do a check on my object.
>> if (myObject.value == null) {myObject.value = -1;}
>> But then you have to do this for all fields in the schema which aren't
>> optional. And that's kind of a pain. It'd be kind of nice if the writer
>> also used the default value from the schema for writing.
>> Thanks,
>> Gary
>> On Feb 19, 2014 10:42 AM, "Wai Yip Tung" <wy@tungwaiyip.info> wrote:
>>> In the schema we can define a "default" value. It is used as default
>>> when reading. If the field is missing from the data when we write, it
>>> results in an error. Is there a counterpart of "default" in writing so that
>>> if the field is missing, the writer just fill in the default value?
>>> Wai Yip


View raw message