[
https://issues.apache.org/jira/browse/AVRO-1590?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14146571#comment-14146571
]
Ryan Blue commented on AVRO-1590:
---------------------------------
The problem is that full name isn't required elsewhere to perform the matching.
If the full name matches or an alias exists, then that works for resolution.
But when resolving two record types without one being wrapped in a union, there
is no requirement that the names must match. Instead, they are matched using
[{{resolveRecords}}|https://github.com/apache/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java#L118]
that just looks at the structure. Because this is the "usual" behavior, I
expected it to work the same way when I had a name change and the record was in
a union with NULL.
Perhaps a simpler summary is:
* Resolving T and Union(NULL, T, ...) works for all types
* Resolving Record(name=A, fields=...) and Record(name=B, fields=...) works if
the fields can be resolved
* Resolving Record(name=A, fields=...) and Union(NULL, Record(name=B,
fields=...)) _doesn't_ work even though both of the above rules seem to be
satisfied
I also think that the behavior isn't quite correct when both record names are
null, although I don't think this is a very common case. If a record with no
name is matched against a union of two records with no name, then the first
branch in the union is always chosen. But we can do slightly better and match
the structure of the records to get the right one.
> [java] AllowNull causes unexpected resolution failure
> -----------------------------------------------------
>
> Key: AVRO-1590
> URL: https://issues.apache.org/jira/browse/AVRO-1590
> Project: Avro
> Issue Type: Bug
> Affects Versions: 1.7.7
> Reporter: Ryan Blue
> Assignee: Ryan Blue
> Attachments: AVRO-1590-1.patch
>
>
> If I try to read data serialized with a hand-written schema using a reflected
> schema generated by AllowNull, even though all of the individual types can be
> read. Here is a failing test:
> {code:java}
> public static class Point {
> double x;
> double y;
> }
> public static class Circle {
> Point center;
> double radius;
> }
> @Test
> public void testAllowNull() throws Exception {
> new SchemaValidatorBuilder()
> .canBeReadStrategy()
> .validateLatest().validate(
> SchemaBuilder.record("Circle").fields()
> .name("center").type().record("Point").fields()
> .requiredDouble("x")
> .requiredDouble("y")
> .endRecord().noDefault()
> .requiredDouble("radius")
> .endRecord(),
> Arrays.asList(ReflectData.AllowNull.get().getSchema(Circle.class)));
> }
> {code}
> The problem is that the {{ResolvingGrammarGenerator}} can't resolve a record
> with a nullable record unless the two have the same [full
> name|https://github.com/apache/avro/blob/trunk/lang/java/avro/src/main/java/org/apache/avro/io/parsing/ResolvingGrammarGenerator.java#L439].
> It is more work, but I think the check should be whether there is a readable
> record in the union. Another alternative is to special case a nullable union
> and allow the record-level resolution only in that case.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)