avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ali Hashemi (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AVRO-1871) Avro compiler generate JAVA enum interfaces but writeEnum expects GenericEnumSymbol
Date Tue, 28 Jun 2016 23:02:10 GMT
Ali Hashemi created AVRO-1871:

             Summary: Avro compiler generate JAVA enum interfaces but writeEnum expects GenericEnumSymbol
                 Key: AVRO-1871
                 URL: https://issues.apache.org/jira/browse/AVRO-1871
             Project: Avro
          Issue Type: Bug
          Components: java
    Affects Versions: 1.8.1
            Reporter: Ali Hashemi

Avro compiler generate an enum JAVA class from an enum Avro type 
and this class is used in the Java class of the records pointing to the enum type. However,
org.apache.avro.generic.GenericDatumWriter.writeEnum expects a GenericEnumSymbol rather than
Java Enum!
This is problem because the class interfaces for Avro messages expect Java Enum and not GenericEnumSymbol!

Consider the following schema:

{"namespace": "com.comp.message",
 "type": "record",
 "name": "TrafficLights",
 "fields": [
        {"name": "id",  "type": "string"},
        {"name": "signal",  "type": "Signals" }

   "namespace": "com.comp.message",
   "type": "enum",
   "symbols" : ["GREEN", "YELLOW", "RED"]

Using maven-avro-plugin to import "Signals" as an external schema, Avro compiler creates the
following constructor for TrafficLights class:
public TrafficLights(java.lang.CharSequence id, com.comp.message.Signals signal){...}

and an Enum class fot the Signals:

package com.comp.message;
public enum Signals {
  public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"Signals\",\"namespace\":\"com.comp.message\",\"symbols\":[\"GREEN\",\"YELLOW\",\"RED\"]}");
  public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }

However, when I try to serialize a TrafficLights message, GenericDatumWriter.writeEnum throws
an exeception:

TrafficLights  mainTrafficLight = new TrafficLights  ("123",  Signals.GREEN);
byte[] msg = new AvroMsgManager( mainTrafficLight .getSchema().toString() ).serialize (mainTrafficLight))

org.apache.avro.AvroTypeException: Not an enum: GREEN
        at org.apache.avro.generic.GenericDatumWriter.writeEnum(GenericDatumWriter.java:164)
        at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:106)
        at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
        at org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:153)
        at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:143)
        at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:105)
        at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
        at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:60)

This message was sent by Atlassian JIRA

View raw message