[ 
https://issues.apache.org/jira/browse/AVRO-1568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14504362#comment-14504362
 ] 

Sachin Goyal commented on AVRO-1568:
------------------------------------

I am not sure how easy it is to construct the actual object by expecting 
object's field-getter APIs presence.
Also, how will the schema be constructed for such a case?

May be you can help me understand with this example:
{code}
class ThirdPartyClass {
  Shape item;
}
class Circle extends Shape { ... }
class Triangle extends Shape { ... }
class Rectangle extends Shape { ... }
class Square extends Rectangle { ... }
// Polygon, Pentagon, Tetrahedron, Sphere, Cylinder etc etc.
{code}

\\
With a class-level API only, the schema of item will be a union of all: Circle, 
Triangle, Rectangle... Cylinder etc.
With a field-level API, I can make an optimization of storing Circles together 
by specifying *"Shape item"* to be of type Circle only.
Same for other shapes.

\\
I agree this is not useful if the application needs to handle all shapes.
But if the application is sure that for some cases, it will handle only a 
subset of shapes, then field-level API would result in much shorter schemas.
(And this is not an uncommon case in my opinion)

\\
Field level API is also especially useful if the Shape class is subclassed by a 
really huge number of classes.

> Allow Java polymorphism in Avro for third-party code
> ----------------------------------------------------
>
>                 Key: AVRO-1568
>                 URL: https://issues.apache.org/jira/browse/AVRO-1568
>             Project: Avro
>          Issue Type: Improvement
>    Affects Versions: 1.7.6
>            Reporter: Sachin Goyal
>
> A large number of Java designs interacting with databases with 
> Hibernate/Couchbase (perhaps, even otherwise) have Java polymorphism of the 
> form:
> {code:java}
> class Base 
> {
>    Integer a = 5;
> }
> class Derived extends Base
> {
>     String b = "Foo";
> }
> class PolymorphicDO
> {
>    Base b = new Derived();
> }
> {code}
> Jackson handles this kind of field by using annotations such as:
> {code}
> @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = 
> JsonTypeInfo.As.PROPERTY, property = "@class”)
> {code}
> If such a thing can be added to Avro, all those Java designs could become 
> immediately usable with Avro. They would also become Hadoop compatible due to 
> AvroSerde.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to