You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by Alexandre Normand <al...@gmail.com> on 2013/04/11 23:51:17 UTC

Support for inheritance in avro IDL?

Hey,
I'm wondering what you guys think of adding support for inheritance in avro IDL. We're starting to see unions of different types in our code and they mostly have the same fields. We're basically using unions to do inheritance except that the code that uses it remains cumbersome. The client code needs to do instanceof just to cast to the proper type in order to retrieve a value that is actually present in all types of the union. 

It seems like this could be hidden from client by just creating a union of all types extending a parent type defined for a field and generating sources with that type.  

Any thoughts?

-- 
Alex


Re: Support for inheritance in avro IDL?

Posted by Alexandre Normand <al...@gmail.com>.
We're also using unions now for patterns like this so it's not terribly high priority. But I'd still like to do this as currently, the client code is not terribly nice to look at with all the casting and instanceofs. I haven't looked at what kind of effort would be involved but I'll create a ticket when I find some time to start work on this. 

Thanks for the feedback Doug.  

-- 
Alex


On Tuesday, 23 April, 2013 at 4:06 PM, Doug Cutting wrote:

> I would not be opposed to adding inheritance in IDL.
> 
> FWIW, another way to represent sub-types is through a union field in
> the "super" record, i.e.:
> 
> record Shape {
> int x;
> int y;
> union subFields { CircleFields, SquareFields }
> }
> 
> record CircleFields {
> int radius;
> }
> 
> record SquareFields {
> int size;
> }
> 
> Then you only need to use instanceof and casts for operations that are
> specific to sub-types.
> 
> Doug
> 
> On Thu, Apr 11, 2013 at 2:51 PM, Alexandre Normand
> <alexandre.normand@gmail.com (mailto:alexandre.normand@gmail.com)> wrote:
> > Hey,
> > I'm wondering what you guys think of adding support for inheritance in avro IDL. We're starting to see unions of different types in our code and they mostly have the same fields. We're basically using unions to do inheritance except that the code that uses it remains cumbersome. The client code needs to do instanceof just to cast to the proper type in order to retrieve a value that is actually present in all types of the union.
> > 
> > It seems like this could be hidden from client by just creating a union of all types extending a parent type defined for a field and generating sources with that type.
> > 
> > Any thoughts?
> > 
> > --
> > Alex
> > 
> 
> 
> 



Re: Support for inheritance in avro IDL?

Posted by Doug Cutting <cu...@apache.org>.
I would not be opposed to adding inheritance in IDL.

FWIW, another way to represent sub-types is through a union field in
the "super" record, i.e.:

record Shape {
  int x;
  int y;
  union subFields { CircleFields, SquareFields }
}

record CircleFields {
  int radius;
}

record SquareFields {
  int size;
}

Then you only need to use instanceof and casts for operations that are
specific to sub-types.

Doug

On Thu, Apr 11, 2013 at 2:51 PM, Alexandre Normand
<al...@gmail.com> wrote:
> Hey,
> I'm wondering what you guys think of adding support for inheritance in avro IDL. We're starting to see unions of different types in our code and they mostly have the same fields. We're basically using unions to do inheritance except that the code that uses it remains cumbersome. The client code needs to do instanceof just to cast to the proper type in order to retrieve a value that is actually present in all types of the union.
>
> It seems like this could be hidden from client by just creating a union of all types extending a parent type defined for a field and generating sources with that type.
>
> Any thoughts?
>
> --
> Alex
>