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

Switch to Threaded View
Avro, mail # dev - Avro enum and passivity.


Copy link to this message
-
Re: Avro enum and passivity.
Doug Cutting 2013-07-16, 00:01
On Mon, Jul 15, 2013 at 3:11 PM, Koduri,Vinay <[EMAIL PROTECTED]> 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
like:

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.

Doug