[
https://issues.apache.org/jira/browse/AVRO-1569?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14357320#comment-14357320
]
Sachin Goyal commented on AVRO-1569:
------------------------------------
{quote}
When resolving the union, we just need to match the non-null case.
{quote}
Since a union is an unrestricted collection of other schemas, matching just the
non-null schema may not be sufficient.
\\
{quote}
This may be related to AllowNull problems that were fixed earlier but haven't
been released yet. See AVRO-1590.
{quote}
I have this patch in my local since I am building from the trunk but still the
above problem persists.
\\
{quote}
why the match isn't succeeding?
{quote}
Problem is with the GenericData.resolveUnion() method which uses the following
logic for records:
{code}
if (isRecord(datum))
return getRecordSchema(datum).getFullName();
{code}
Now the schema is of the type \["null", "Base"\] because during
schema-generation, only the class information was available.
Hence no mentioned of Derived in the schema. Interestingly, ReflectData without
AllowNull succeeds here because it does not have to do a resolveUnion() and it
just writes out the Derived object as a BaseClass (which maybe acceptable for
some cases). This fix makes sure that ReflectData.AllowNull is able to behave
the same as ReflectData without AllowNull by serializing just the base-part of
the Derived.
\\
AVRO-1568 handles the serialization of Derived as a complete Derived object.
> ReflectData.AllowNull fails with polymorphism
> ---------------------------------------------
>
> Key: AVRO-1569
> URL: https://issues.apache.org/jira/browse/AVRO-1569
> Project: Avro
> Issue Type: Bug
> Affects Versions: 1.7.6
> Reporter: Sachin Goyal
>
> UnresolvedUnionException is thrown if the following structure is serialized
> with ReflectData.AllowNull
> (Plain ReflectData works fine)
> {code}
> class Base
> {
> Integer a = 5;
> }
> class Derived extends Base
> {
> String b = "Foo";
> }
> class PolymorphicDO
> {
> Base obj = new Derived();
> }
> // Serialization code:
> ReflectData rdata = ReflectData.AllowNull.get();
> Schema schema = rdata.getSchema(PolymorphicDO.class);
> ReflectDatumWriter<T> datumWriter = new ReflectDatumWriter
> (PolymorphicDO.class, rdata);
> DataFileWriter<T> fileWriter = new DataFileWriter<T> (datumWriter);
> fileWriter.create(schema, new ByteArrayOutputStream());
> fileWriter.append(new PolymorphicDO());
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)