avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christophe Taton <ta...@wibidata.com>
Subject Re: default write value in schema?
Date Wed, 19 Feb 2014 17:39:59 GMT
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
>>
>

Mime
View raw message