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 GitHub Bot (JIRA)" <ji...@apache.org> on 2018/12/10 20:16:00 UTC

[jira] [Commented] (AVRO-2058) ReflectData#isNonStringMap returns true for Utf8 keys

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

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

dkulp closed pull request #237: [AVRO-2058] ReflectData#isNonStringMap returns true for Utf8 keys
URL: https://github.com/apache/avro/pull/237
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
index 27d11a316..8f8369ddb 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
@@ -21,10 +21,12 @@
 import java.io.UnsupportedEncodingException;
 
 import org.apache.avro.io.BinaryData;
+import org.apache.avro.reflect.Stringable;
 
 /** A Utf8 string.  Unlike {@link String}, instances are mutable.  This is more
  * efficient than {@link String} when reading or writing a sequence of values,
  * as a single instance may be reused. */
+@Stringable
 public class Utf8 implements Comparable<Utf8>, CharSequence {
   private static final byte[] EMPTY = new byte[0];
   private static final Charset UTF8 = Charset.forName("UTF-8");
diff --git a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
index afe7f08ae..35b957a70 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java
@@ -47,6 +47,7 @@
 import org.apache.avro.io.Encoder;
 import org.apache.avro.io.EncoderFactory;
 import org.apache.avro.reflect.TestReflect.SampleRecord.AnotherSampleRecord;
+import org.apache.avro.util.Utf8;
 import org.codehaus.jackson.node.NullNode;
 import org.junit.Test;
 
@@ -123,6 +124,15 @@
     assertEquals(1, data.resolveUnion(s, new HashMap<String,Float>()));
   }
 
+  @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));
+  }
+
   @Test public void testUnionWithFixed() {
     Schema s = new Schema.Parser().parse
         ("[\"null\", {\"type\":\"fixed\",\"name\":\"f\",\"size\":1}]");


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> ReflectData#isNonStringMap returns true for Utf8 keys
> -----------------------------------------------------
>
>                 Key: AVRO-2058
>                 URL: https://issues.apache.org/jira/browse/AVRO-2058
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.2
>            Reporter: Sam Schlegel
>            Assignee: 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
(v7.6.3#76005)