avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Graham <billgra...@gmail.com>
Subject Combining schemas
Date Tue, 09 Aug 2011 18:15:29 GMT

I'm trying to create a schema that references a type defined in another
schema and I'm having some troubles. Is there an easy way to do this?

My test schemas look like this:

$ cat position.avsc
{"type":"enum", "name": "Position", "namespace": "avro.examples.baseball",
 "symbols": ["P", "C", "B1", "B2", "B3", "SS", "LF", "CF", "RF", "DH"]

$ cat player.avsc
{"type":"record", "name":"Player", "namespace": "avro.examples.baseball",
 "fields": [
  {"name": "number", "type": "int"},
  {"name": "first_name", "type": "string"},
  {"name": "last_name", "type": "string"},
  {"name": "position", "type": {"type": "array", "items":
"avro.examples.baseball.Position"} }

I've read this thread (
and tried using IDL like so with no luck:

$ cat baseball.avdl
protocol Baseball {
  import schema "position.avsc";
  import schema "player.avsc";

$ java -jar avro-tools-1.5.1.jar idl  baseball.avdl baseball.avpr
Exception in thread "main" org.apache.avro.SchemaParseException: Undefined
name: "avro.examples.baseball.Position"
        at org.apache.avro.Schema.parse(Schema.java:979)
        at org.apache.avro.Schema.parse(Schema.java:1052)
        at org.apache.avro.Schema.parse(Schema.java:1021)
        at org.apache.avro.Schema.parse(Schema.java:884)
        at org.apache.avro.compiler.idl.Idl.ImportSchema(Idl.java:388)
        at org.apache.avro.compiler.idl.Idl.ProtocolBody(Idl.java:320)
        at org.apache.avro.compiler.idl.Idl.CompilationUnit(Idl.java:84)

I also saw this blog post (
http://www.infoq.com/articles/ApacheAvro#_ftnref6_7758) where the author had
to write some nasty String.replace(..) code to combine schemas, but there's
got to be a better way that this.

Also FYI, it seems enum values can't start with numbers (i.e. '1B'). Is this
a know issue or a feature? I haven't seen it documented anywhere. You get an
error like this if the value starts with a number:

org.apache.avro.SchemaParseException: Illegal initial character


View raw message