avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matt Hurne (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (AVRO-1870) Avro compiler generate JAVA enum interfaces but writeEnum expects GenericEnumSymbol
Date Fri, 15 Jul 2016 13:03:20 GMT

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

Matt Hurne edited comment on AVRO-1870 at 7/15/16 1:02 PM:
-----------------------------------------------------------

Ok - that point wasn't all that clear in the ticket description. Where did AvroMsgManager
come from? I don't believe it is part of Avro itself.


was (Author: mhurne):
Ok - that point wasn't really clear in the ticket description. Where did AvroMsgManager come
from? I don't believe it is part of Avro itself.

> 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