A protocol definition can include multiple schema definitions, where each schema defined can refer to previously defined schema definitions. A protocol need not include any messages, but can be used simply as a vehicle to define a set of schemas.
Avro IDL permits imports of external schemas and protocols: http://avro.apache.org/docs/current/idl.html#imports If none of these are appropriate, you can use a pre-processor like cpp or m4 to textually include schemas within other schemas. Doug On 03/11/2011 01:21 PM, Vivek Hungund wrote: > Hi, > > I want to be able to import and share a schema with multiple other > schemas. The schema is defined as such: > > { > "_namespace_" : "test.avro", > "name" : "Address", > "type" : "record", > "fields" : [ > {"name" : "address1" , "type" : "string" }, > {"name" : "address2" , "type" : "string" }, > {"name" : "city" , "type" : "string" }, > {"name" : "state" , "type" : "string" }, > {"name" : "_zip_" , "type" : "_int_" }, > {"name" : "zip4", "type": "_int_" } > ] > } > > And I’d like to refer to an Address in other schemas, e.g.: > > { > "namespace": "test.avro", > "name" : "User", > "type" : "record", > "fields" : [ > { "name": "name", "type": "string" }, > { "name": "address", "type": { "type" : > " test.avro.Address" } } > ] > } > > Or > > { > "namespace": "test.avro", > "name" : "Business", > "type" : "record", > "fields" : [ > { "name": "businessName", "type": > "string" }, > { "name": "address", "type": { "type" : > " test.avro.Address" } } > ] > } > > > However when I try this I get the following error: > _org.apache.avro.SchemaParseException_: Type not supported: Address > > > Basically I want to have a generic Address schema that can be imported > by a number of different other schemas. The motivation is to avoid > having to maintain an Address record for every User, Business, etc. If > this is not possible, can someone recommend a workaround? Is my syntax > incorrect? > > Thanks in advance.
