You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF subversion and git services (JIRA)" <ji...@apache.org> on 2013/09/27 22:13:03 UTC

[jira] [Commented] (AVRO-1377) Fields with certained name-spaced schemas (enum, union) inside an un-name-spaced record schema can cause the schema to be serialized incorrectly

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

ASF subversion and git services commented on AVRO-1377:
-------------------------------------------------------

Commit 1527057 from [~cutting] in branch 'avro/trunk'
[ https://svn.apache.org/r1527057 ]

AVRO-1377. Java: Fix a bug in Schema#toString() when a namespaced enum or fixed is defined within an un-namespaced record.  Contributed by Graham Sanderson.
                
> Fields with certained name-spaced schemas (enum, union) inside an un-name-spaced record schema can cause the schema to be serialized incorrectly
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: AVRO-1377
>                 URL: https://issues.apache.org/jira/browse/AVRO-1377
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.5
>            Reporter: graham sanderson
>             Fix For: 1.7.6
>
>         Attachments: AVRO-1377.patch
>
>
> From email thread on user list
> {code}
> Here is a condensed example of a problem I just came across
>    @Test
>    void testNamespaceBleed() throws Exception {
>        Schema schema = SchemaBuilder.record("test").fields()
>                .name("field1").type().enumeration("Bar").namespace("com.foo").symbols("x").noDefault()
>                .name("field2").type().record("Humbug").namespace("com.foo").fields().endRecord().noDefault()
>                .endRecord();
>        String schemaString = schema.toString(true);
>        Schema schema2 = new Schema.Parser().parse(schemaString);
>        Assert.assertEquals(schema, schema2); // one would hope this were true
>    }
> {code}
> Basically the use case (which may not be very common) is with the first (namespaced) schema in a record without a namespace being an enum. Because the serialization of the enum schema does not save and restore the namespace, it becomes the default namespace (for serialization) of other fields that follow in the same record (so field2 is written without a namespace since it is in the default namespace, but when the schema is deserialized the same bug does not occur and so it appears a "Humbug" rather than "com.foo.Humbug")
> Note, the following (and of course most others) all work
> {code}
>    @Test
>    void testNoNamespaceBleed() throws Exception {
>        // works because the enclosing record has a namespace
>        Schema schema = SchemaBuilder.record("test").namespace("com.foo").fields() 
>                .name("field1").type().enumeration("Bar").namespace("com.foo").symbols("x").noDefault()
>                .name("field2").type().record("Humbug").namespace("com.foo").fields().endRecord().noDefault()
>                .endRecord();
>        String schemaString = schema.toString(true);
>        Schema schema2 = new Schema.Parser().parse(schemaString);
>        Assert.assertEquals(schema,schema2);
>        // works because the enclosing record has a namespace (even though different)
>        schema = SchemaBuilder.record("test").namespace("com.bar").fields() 
>                .name("field1").type().enumeration("Bar").namespace("com.foo").symbols("x").noDefault()
>                .name("field2").type().record("Humbug").namespace("com.foo").fields().endRecord().noDefault()
>                .endRecord();
>        schemaString = schema.toString(true);
>        schema2 = new Schema.Parser().parse(schemaString);
>        Assert.assertEquals(schema,schema2);
>        // works because the enum and the field are in different namespaces
>        schema = SchemaBuilder.record("test").fields()
>                .name("field1").type().enumeration("Bar").namespace("com.bar").symbols("x").noDefault()
>                .name("field2").type().record("Humbug").namespace("com.foo").fields().endRecord().noDefault()
>                .endRecord();
>        schemaString = schema.toString(true);
>        schema2 = new Schema.Parser().parse(schemaString);
>        Assert.assertEquals(schema,schema2);
>    }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira