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

Switch to Threaded View
Avro >> mail # user >> schema defaults not reflected in generated objects (1.3.2)

Copy link to this message
Re: schema defaults not reflected in generated objects (1.3.2)
We could crash on serialization if the fields haven't been explicitly
set, but I'm +1 for the default values to be represented at generated
object construction time.

-- Philip

On Mon, Jun 7, 2010 at 3:11 PM, Bill de hOra <[EMAIL PROTECTED]> wrote:
> Scott Carey wrote:
>> No, it should not initialize the field to the default.
>> Default values are for readers, not writers.   The intended use case is
>> schema evolution.
> This means writers can't leverage schema defaults, so writers should do
> something like this?
>  Message message = new Message();
>  // no defaults set
>  String quux = message
>     .getSchema()
>     .getField("foo")
>     .defaultValue()
>     .getTextValue();
>  message.foo=new Utf8(quux);
> [ignoring that the writer needs to know the schema type]. I suspect people
> will just write in garbage (like empty strings).
>> A writer must always correctly provide
>> data for all of the fields in the schema it declared
>> it is writing.
> Why is it incorrect to not provide defaults when defaults are  part of the
> schema author's intention? Or put another way, why is reader/writer
> asymmetry a goal under a given schema?
> I see in the code that SpecificDatumWriter/GenericDatumWriter is passed the
> Schema - By all means crash on fields with no defaults, but I'm not clear on
> what harm is done by using default field data. The current code seems
> fragile in comparison.
> Bill