avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Binglin Chang <decst...@gmail.com>
Subject Re: How to add optional new record fields and/or new methods in avro-ipc?
Date Wed, 19 Oct 2011 12:48:02 GMT
Thanks for the reply.
I did some simple tests related to default "default value" for UnionSchema,
and traced into source code:

Schema.java

static Schema parse(JsonNode schema, Names names)

1147          Field f = new Field(fieldName, fieldSchema,

1148                              fieldDoc, field.get("default"), order);
It seems that there is no special handle for UnionSchema Field to get a
proper default value, and
ReflectData do not infer default values for fields, at least union fields(I
think this is a bug):
ReflectData.java

291              fields.add(new Schema.Field(field.getName(),

292                  fieldSchema, null /* doc */, null));
And finally, I think annotation like @Default(..) is needed.


On Wed, Oct 19, 2011 at 5:36 AM, Doug Cutting <cutting@apache.org> wrote:

> On 10/18/2011 11:40 AM, Scott Carey wrote:
> > I'm not sure that I understand "The default value for a union is the
> > default value for its first branch."
> > Defaults don't apply to any types in a union, only to fields on a record.
> > So the Schema ["Foo", "Bar"] can have no default, nor can any of its
> > branches.
>
> From the spec's definition of default values:
>
> "Permitted values depend on the field's schema type, according to the
> table below. Default values for union fields correspond to the first
> schema in the union."
>
> So the default value for a field with a union type as its value is
> assumed to be of the type of the first element of that union.  If the
> first element of that union is "null", then the type of the default
> value must be "null" hence the default value itself can only be "null".
>  So the question is whether we require that to be stated explicitly in
> the schema.  I assumed that we did not.  Either way, we should clarify
> the spec around this.
>
> We could continue to insist that, if no default value is explicitly
> specified in the reader's schema, and the writer's schema lacks a field,
> then an error is thrown.  Or we could say that the default value for
> default values is null, so that if the reader adds a field that's a
> union with "null" as its first branch then no default value need be
> present.
>
> Doug
>

Mime
View raw message