Doug Cutting wrote:
On 06/07/2010 01:53 PM, Bill de hOra wrote:
I.m wondering if I'm missing an incantation for 'compile
schema/protocol' in Avro tools to handle defaults. Given this schema,

In Avro, default values are used by a reader when a writer's schema lacks a field. This permits one to add a new field and still process data written before that field was added, provided one specifies a default value for the new field. Similarly, if one removes a field, older code may still process the data, provided it has a default value.

This is related but not the same as the default value for a Java instance. When one manually specifies a default value for a field in Java, one does not do this not primarily in order to future-proof the class, but typically so that one can avoid having to explicitly set the value somewhere else. What both concepts have in common is that they permit a developer to provide a reasonable value to be used when no more specific value is known.

So it might be a useful feature if Java instance default values were acquired from the schema. For one thing, folks seem to expect it. But, from Avro's perspective, I don't think it's a bug.

Does that make sense?

It does if Avro == specification (my reply to Scott is quizzing the Java generator code btw, not the spec).

On that ground, I can't argue that the asymmetry is a bug, but it might turn out to be fragile, even if it's stated somewhere in the spec that writers are required to roundtrip defaults back to the server (the spec isn't explicit wrt defaults for writers, or whether schema should be shipped with data in that case).

Bill

Reply via email to