avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Carey <sc...@richrelevance.com>
Subject Re: How to reference previously defined enum in avsc file?
Date Fri, 11 Mar 2011 18:28:20 GMT
You need an array of JSON objects in the avsc file, something like:

[
  {
    "namespace": "def.al.pha.bet",
    "type": "enum",
    "name": "KnownLetters",
    "doc": "Specifies known types of letters",
    "symbols": ["A", "B", "C", "D", "E"]
  },
  {
    "namespace": "def.note.pad",
    "type": "record",
    "name": "Page",
    "doc": "Object definition of a Page composed of alphabet",
    "fields": [
        {"name": "letter",  "type": "KnownLetters"}
    ]
  }
}



What you have is one JSON object, with "name" (and other properties)
declared twice, and the parser took the last one.

If the two objects are in a different namespace, you might need a fully
qualified name to reference them too.

On 3/10/11 8:04 PM, "Aleksey Maslov" <Aleksey.Maslov@Lab49.com> wrote:

>Hi, 
>[i don't see my original post - but if you seen this already, I appologise
>for re-post]
>
>I am trying to define several objects in avsc files and compile the schema
>using avro-1.4.1; 
>i have several questions;
>
>1. Is it true that all objects MUST be defined in 1 huge file if I want to
>reference previously defined ones?
>(sounds a bit messy if you have dozens of objects to define, but ok);
>
>2. I am having a problem defining a field of type enum (previously defined
>in same avsc file), with error:
> Exception in thread "main" org.apache.avro.SchemaParseException:
>"KnownLetters" is not a defined name.
>
>
>my avsc file contents:
>
>{ 
>    "namespace": "def.al.pha.bet",
>    "type": "enum",
>    "name": "KnownLetters",
>    "doc": "Specifies known types of letters",
>    "symbols": ["A", "B", "C", "D", "E"],
>    
>    "namespace": "def.note.pad",
>    "type": "record",
>    "name": "Page",
>    "doc": "Object definition of a Page composed of alphabet",
>    "fields": [ 
>        {"name": "letter",  "type": "KnownLetters"}
>    ] 
>} 
>
>How could this be achived? What am i missing?
>
>3. I am observing strange namespace related behavior; to experiment, in
>the
>above avsc definition I defined letter as "int" (just to keep going), and
>found that only 1 of the two objects are being generated (the Page.java);
>the enum is not generated at all, and i get no errors on the command line;
>why is that? 
>
>my invocation is: 
>> java -jar ..\lib\avro-tools-1.4.1.jar compile schema ..\def\test.avsc
>>..\ 
>
>Thanks; 
>
>
>--
>View this message in context:
>http://apache-avro.679487.n3.nabble.com/How-to-reference-previously-define
>d-enum-in-avsc-file-tp2663512p2663512.html
>Sent from the Avro - Users mailing list archive at Nabble.com.


Mime
View raw message