avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Carey <scottca...@apache.org>
Subject Re: Combining schemas
Date Tue, 09 Aug 2011 21:20:57 GMT
On 8/9/11 1:45 PM, "Bill Graham" <billgraham@gmail.com> wrote:

> Thanks Scott and Doug, see follow up below.
> 
> On Tue, Aug 9, 2011 at 11:42 AM, Scott Carey <scottcarey@apache.org> wrote:
>> On 8/9/11 11:15 AM, "Bill Graham" <billgraham@gmail.com> wrote:
>> 
>>> 
>>  Using the lower level Avro API you can parse the files yourself in an order
>> that will work.
>   
> How exactly would the approach work where you parse files in
> reverse-dependency order work? This is something I'd like to explore and maybe
> contribute a helper for. I've tried a few combinations of this approach to no
> avail:
> 
>         Schema schema1 = Schema.parse(new
> File("examples/java/avro/position.avsc"));
>         Schema schema2 = schema1.parse(new
> File("examples/java/avro/player.avsc"));
> 

I was mistaken.  The methods to do this are not public.

The internals of the parser in Schema.java use a hidden inner class, Names.
Names is a LinkedHashMap<Name, Schema> .

It should be relatively easy to add a signature to Schema.java along the
lines:

parse(File schema, Map<Name, Schema> context);

This would: 
  for the given context:
     validate it (each Name should match a Named schema with the same name)
     place names into a Names instance and parse the schema with the Names
context
  on return from the internal parse, copy the contents of the Names object
into the provided context

Alternatively we could make the Names class public, clean it up and document
it, and expose parse methods that take Names objects.


Then you could do:

Map<Name, Schema> context = new HashMap<Name, Schema>();
Schema schema1 = Schema.parse(new File("examples/java/avro/position.avsc",
context));
Schema schema2 = schema1.parse(new File("examples/java/avro/player.avsc",
context));






Mime
View raw message