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

ASF GitHub Bot commented on AVRO-2058:
--------------------------------------

GitHub user samschlegel opened a pull request:

    https://github.com/apache/avro/pull/237

    [AVRO-2058] ReflectData#isNonStringMap returns true for Utf8 keys

    https://issues.apache.org/jira/browse/AVRO-2058
    
    Since `Utf8` does not have an `Stringable` notation, and is not in 
`SpecificData#stringableClasses`, `ReflectData#isNonStringMap` returns true. 
This also causes `ReflectData#isArray` to return true for maps with Utf8 keys, 
and thus `GenericData#resolveUnion` fails as well. This ultimately causes 
`ReflectData#write` to fail for schemas that contain a union that contains a 
map, where the data uses Utf8 for strings.
    
    This following test case reproduces the issue:
    
    ```java
      @Test public void testUnionWithMapWithUtf8Keys() {
        Schema s = new Schema.Parser().parse
          ("[\"null\", {\"type\":\"map\",\"values\":\"float\"}]");
        GenericData data = ReflectData.get();
        HashMap<Utf8,Float> map = new HashMap<Utf8,Float>();
        map.put(new Utf8("foo"), 1.0f);
        assertEquals(1, data.resolveUnion(s, map));
      }
    ```


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/samschlegel/avro master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/avro/pull/237.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #237
    
----
commit 8852da40e7a0ee58d9b027173a4972e7e71b432d
Author: Sam Schlegel <g...@lutin.us>
Date:   2017-07-27T02:20:51Z

    Add failing test

commit 15fbb40944dc15a37569aa6a3d2e93db0e085af0
Author: Sam Schlegel <g...@lutin.us>
Date:   2017-07-27T02:23:21Z

    Add Stringable annotation

----


> ReflectData#isNonStringMap returns true for Utf8 keys
> -----------------------------------------------------
>
>                 Key: AVRO-2058
>                 URL: https://issues.apache.org/jira/browse/AVRO-2058
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.2
>            Reporter: Sam Schlegel
>            Priority: Critical
>         Attachments: AVRO-2058.patch
>
>
> Since {{Utf8}} does not have an {{Stringable}} notation, and is not in 
> {{SpecificData#stringableClasses}}, {{ReflectData#isNonStringMap}} returns 
> true. This also causes {{ReflectData#isArray}} to return true for maps with 
> Utf8 keys, and thus {{GenericData#resolveUnion}} fails as well. This 
> ultimately causes {{ReflectData#write}} to fail for schemas that contain a 
> union that contains a map, where the data uses Utf8 for strings.
> This following test case reproduces the issue:
> {code:java}
>   @Test public void testUnionWithMapWithUtf8Keys() {
>     Schema s = new Schema.Parser().parse
>       ("[\"null\", {\"type\":\"map\",\"values\":\"float\"}]");
>     GenericData data = ReflectData.get();
>     HashMap<Utf8,Float> map = new HashMap<Utf8,Float>();
>     map.put(new Utf8("foo"), 1.0f);
>     assertEquals(1, data.resolveUnion(s, map));
>   }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to