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