avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject [1/2] avro git commit: [fix] get/set defaults for fixed.
Date Tue, 28 Feb 2017 04:24:38 GMT
Repository: avro
Updated Branches:
  refs/heads/master 273556423 -> 43297652d


[fix] get/set defaults for fixed.

Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/db6bb9d7
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/db6bb9d7
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/db6bb9d7

Branch: refs/heads/master
Commit: db6bb9d7a9f404e907d12a1380b65caac776b8a3
Parents: 2735564
Author: Zoltan Farkas <zolyfarkas@yahoo.com>
Authored: Tue Feb 7 13:52:08 2017 -0500
Committer: Thiruvalluvan M G <thiru@startsmartlabs.com>
Committed: Tue Feb 28 09:23:04 2017 +0530

----------------------------------------------------------------------
 .../main/java/org/apache/avro/SchemaBuilder.java |  4 ++++
 .../apache/avro/util/internal/JacksonUtils.java  |  3 ++-
 .../src/test/java/org/apache/avro/TestFixed.java | 19 +++++++++++++++++++
 3 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/db6bb9d7/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java b/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java
index f1a1faa..ce038d4 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/SchemaBuilder.java
@@ -2587,6 +2587,10 @@ public class SchemaBuilder {
         s = new String(data, "ISO-8859-1");
         char[] quoted = JsonStringEncoder.getInstance().quoteAsString(s);
         s = "\"" + new String(quoted) + "\"";
+      } else if (o instanceof byte[]) {
+        s = new String((byte[]) o, "ISO-8859-1");
+        char[] quoted = JsonStringEncoder.getInstance().quoteAsString(s);
+        s = '\"' + new String(quoted) + '\"';
       } else {
         s = GenericData.get().toString(o);
       }

http://git-wip-us.apache.org/repos/asf/avro/blob/db6bb9d7/lang/java/avro/src/main/java/org/apache/avro/util/internal/JacksonUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/internal/JacksonUtils.java
b/lang/java/avro/src/main/java/org/apache/avro/util/internal/JacksonUtils.java
index ca98e4c..49b939e 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/internal/JacksonUtils.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/internal/JacksonUtils.java
@@ -120,7 +120,8 @@ public class JacksonUtils {
       if (schema == null || schema.getType().equals(Schema.Type.STRING) ||
           schema.getType().equals(Schema.Type.ENUM)) {
         return jsonNode.asText();
-      } else if (schema.getType().equals(Schema.Type.BYTES)) {
+      } else if (schema.getType().equals(Schema.Type.BYTES)
+              || schema.getType().equals(Schema.Type.FIXED)) {
         try {
           return jsonNode.getTextValue().getBytes(BYTES_CHARSET);
         } catch (UnsupportedEncodingException e) {

http://git-wip-us.apache.org/repos/asf/avro/blob/db6bb9d7/lang/java/avro/src/test/java/org/apache/avro/TestFixed.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestFixed.java b/lang/java/avro/src/test/java/org/apache/avro/TestFixed.java
new file mode 100644
index 0000000..da0ab5f
--- /dev/null
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestFixed.java
@@ -0,0 +1,19 @@
+package org.apache.avro;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestFixed {
+
+
+  @Test
+  public void testFixedDefaultValueDrop() {
+    Schema md5 = SchemaBuilder.builder().fixed("MD5").size(16);
+    Schema frec = SchemaBuilder.builder().record("test")
+            .fields().name("hash").type(md5).withDefault(new byte[16]).endRecord();
+    Schema.Field field = frec.getField("hash");
+    Assert.assertNotNull(field.defaultVal());
+    Assert.assertArrayEquals(new byte[16], (byte[]) field.defaultVal());
+  }
+
+}


Mime
View raw message