avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: How to reference previously defined enum in avsc file?
Date Fri, 11 Mar 2011 18:16:37 GMT
On 03/10/2011 08:04 PM, Aleksey Maslov wrote:
> 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); 

You can import schemas, protocols and other IDL files into an IDL file:

http://avro.apache.org/docs/1.4.1/idl.html#imports

> 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? 

You appear to have two schemas appended in a single JSON object.
Instead you should have two json objects, either as two separate .avsc
files or in a single .avpr file.  (You can also define multiple,
dependent types in a single .avdl file.)

> 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? 

I think this is another result of the above problem.


Doug

Mime
View raw message