avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject [5/7] avro git commit: AVRO-1929: Java: SchemaCompatibility fails to recognize string<->bytes promotion. Contributed by Anders Sundelin.
Date Fri, 18 Aug 2017 14:57:29 GMT
AVRO-1929: Java: SchemaCompatibility fails to recognize string<->bytes promotion.  Contributed
by Anders Sundelin.

(cherry picked from commit 1b91c06e92c4b5dd8e3a3e936b36e54fb9c9e023)


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

Branch: refs/heads/branch-1.7
Commit: 492ab98be6b718df6439d782c8b208d11cdf000a
Parents: 7941a14
Author: Doug Cutting <cutting@apache.org>
Authored: Thu Oct 6 15:07:12 2016 -0700
Committer: Sean Busbey <busbey@apache.org>
Committed: Fri Aug 18 09:56:49 2017 -0500

----------------------------------------------------------------------
 .../main/java/org/apache/avro/SchemaCompatibility.java | 13 +++++++++++--
 .../java/org/apache/avro/TestSchemaCompatibility.java  |  8 +++++---
 2 files changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/492ab98b/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java b/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
index e62ea0b..9ac6dc8 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/SchemaCompatibility.java
@@ -379,8 +379,17 @@ public class SchemaCompatibility {
                 ? SchemaCompatibilityType.COMPATIBLE
                 : SchemaCompatibilityType.INCOMPATIBLE;
           }
-          case BYTES: return SchemaCompatibilityType.INCOMPATIBLE;
-          case STRING: return SchemaCompatibilityType.INCOMPATIBLE;
+          case BYTES: {
+              return (writer.getType() == Type.STRING)
+                      ? SchemaCompatibilityType.COMPATIBLE
+                      : SchemaCompatibilityType.INCOMPATIBLE;
+                }
+          case STRING: {
+              return (writer.getType() == Type.BYTES)
+                  ? SchemaCompatibilityType.COMPATIBLE
+                  : SchemaCompatibilityType.INCOMPATIBLE;
+            }
+
           case ARRAY: return SchemaCompatibilityType.INCOMPATIBLE;
           case MAP: return SchemaCompatibilityType.INCOMPATIBLE;
           case FIXED: return SchemaCompatibilityType.INCOMPATIBLE;

http://git-wip-us.apache.org/repos/asf/avro/blob/492ab98b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java
index 61524e5..25a74e1 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaCompatibility.java
@@ -17,8 +17,8 @@
  */
 package org.apache.avro;
 
-import static junit.framework.Assert.assertEquals;
 import static org.apache.avro.SchemaCompatibility.checkReaderWriterCompatibility;
+import static org.junit.Assert.assertEquals;
 
 import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
@@ -352,6 +352,10 @@ public class TestSchemaCompatibility {
 
       new ReaderWriter(ENUM1_AB_SCHEMA, ENUM1_AB_SCHEMA),
       new ReaderWriter(ENUM1_ABC_SCHEMA, ENUM1_AB_SCHEMA),
+      
+      // String-to/from-bytes, introduced in Avro 1.7.7
+      new ReaderWriter(STRING_SCHEMA, BYTES_SCHEMA),
+      new ReaderWriter(BYTES_SCHEMA, STRING_SCHEMA),
 
       // Tests involving unions:
       new ReaderWriter(EMPTY_UNION_SCHEMA, EMPTY_UNION_SCHEMA),
@@ -412,11 +416,9 @@ public class TestSchemaCompatibility {
 
       new ReaderWriter(STRING_SCHEMA, BOOLEAN_SCHEMA),
       new ReaderWriter(STRING_SCHEMA, INT_SCHEMA),
-      new ReaderWriter(STRING_SCHEMA, BYTES_SCHEMA),
 
       new ReaderWriter(BYTES_SCHEMA, NULL_SCHEMA),
       new ReaderWriter(BYTES_SCHEMA, INT_SCHEMA),
-      new ReaderWriter(BYTES_SCHEMA, STRING_SCHEMA),
 
       new ReaderWriter(INT_ARRAY_SCHEMA, LONG_ARRAY_SCHEMA),
       new ReaderWriter(INT_MAP_SCHEMA, INT_ARRAY_SCHEMA),


Mime
View raw message