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

Doug Cutting commented on AVRO-1590:
------------------------------------

bq. Resolving Record(name=A, fields=...) and Record(name=B, fields=...) works 
if the fields can be resolved

This is a deviation from the specification.  Record names are meant to match, 
including namespace.  For example one have a union that contains records 
v1.Purchase and v2.Purchase.

Aliases were added to permit folks to read records in with changed names.  The 
namespace is part of the name.  So it seems to me that aliases are a better way 
to handle this, rather than rely on a loose implementation.

Records will null names are not permitted in the spec.  The Java implementation 
uses them internally to implement message parameter lists, but the schema 
parser shouldn't parse them.

We could: 
 # implement the spec even more loosely, e.g., first looking for the record in 
a union whose full name matches, then one whose short name matches and if both 
of those fail use the first record in the union.
 # tighten the implementation to better enforce the specification, breaking 
applications that depend on this.
 # change the specification to permit loose matching when exact match fails.
 # leave things as is.

It would be good to look how Perl, Python, Ruby, C & C++ implement this.  In a 
union with multiple records, how do they select a match?  My guess is that some 
are strict & some are loose.

By Postel's law, a loose implementation is acceptable, so I lean towards 1 or 4.

> [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)

Reply via email to