avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ryan Blue (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-1590) [java] AllowNull causes unexpected resolution failure
Date Wed, 24 Sep 2014 19:54:34 GMT

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

Ryan Blue commented on AVRO-1590:
---------------------------------

Python at least uses the strict check that the full names match (see io lines [457|https://github.com/apache/avro/blob/trunk/lang/py/src/avro/io.py#L457]
and [388|https://github.com/apache/avro/blob/trunk/lang/py/src/avro/io.py#L388]).

I think #1 works. I like matching just the short name to support relocations more easily,
and using the first record in the union fixes the cases where I'm seeing this because AllowNull
is adding unions everywhere. If we want an even more loose implementation, I can update this
patch so that it checks full name, then short name, and then structure rather than choosing
the first record.

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

Mime
View raw message