avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: Avro enum and passivity.
Date Tue, 16 Jul 2013 00:01:58 GMT
On Mon, Jul 15, 2013 at 3:11 PM, Koduri,Vinay <Vinay.Koduri@cerner.com> wrote:
> I am curios why this was designed to be non-passive, rather than simply ignoring the
new value or giving a "special" unsupported enum value if the enum is required.

The standard resolution mechanism is fairly strict, not permitting
missing fields or extra enum symbols.

There are schema conventions one might adopt to loosen this.  One
could add an "UNSPECIFIED" value to one's enums, or one could make the
enum's optional (i.e., a union with null).

We could develop a DatumReader that uses a non-standard resolution
mechanism.  For example, one might use GenericDatumReader with the
writer's schema to read the full written record, then use modified
templates so that the compiler creates wrappers around this generic
representation.  For example, the generated code for a Card might look

class Card {
  private GenericRecord value;
  public Suit getSuit() { return
Suit.valueOf(value.getField("suit").toString()); }

This would permit the data to be read and only throw an exception when
one tried to access a record with the undefined symbol.


View raw message