avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Busbey (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-1870) Avro compiler generate JAVA enum interfaces but writeEnum expects GenericEnumSymbol
Date Mon, 25 Jul 2016 15:27:20 GMT

    [ https://issues.apache.org/jira/browse/AVRO-1870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15392097#comment-15392097
] 

Sean Busbey commented on AVRO-1870:
-----------------------------------

I think historically Specific API objects happened to work with the GenericDatumWriter, even
though we don't claim that they will. If you're going to process both Specific and Generic
API objects, you should use SpecificDatumWriter. All the better if you can differentiate between
Generic and Specific and use the appropriate writer with each.

> Avro compiler generate JAVA enum interfaces but writeEnum expects GenericEnumSymbol
> -----------------------------------------------------------------------------------
>
>                 Key: AVRO-1870
>                 URL: https://issues.apache.org/jira/browse/AVRO-1870
>             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:
> TrafficLights.avsc:
> {"namespace": "com.comp.message",
>  "type": "record",
>  "name": "TrafficLights",
>  "fields": [
>         {"name": "id",  "type": "string"},
>         {"name": "signal",  "type": "Signals" }
>  ]
> }
> Signals.avsc:
> {
>    "namespace": "com.comp.message",
>    "type": "enum",
>    "name":"Signals",
>    "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;
> @SuppressWarnings("all")
> @org.apache.avro.specific.AvroGenerated
> public enum Signals {
>   GREEN, YELLOW, RED  ;
>   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
(v6.3.4#6332)

Mime
View raw message