avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [28/35] avro git commit: AVRO-1929: Java: SchemaCompatibility fails to recognize string<->bytes promotion. Contributed by Anders Sundelin.
Date Sat, 05 Nov 2016 20:20:45 GMT
AVRO-1929: Java: SchemaCompatibility fails to recognize string<->bytes promotion.  Contributed
by Anders Sundelin.


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

Branch: refs/heads/branch-1.8
Commit: 1b91c06e92c4b5dd8e3a3e936b36e54fb9c9e023
Parents: f02db39
Author: Doug Cutting <cutting@apache.org>
Authored: Thu Oct 6 15:07:12 2016 -0700
Committer: Ryan Blue <blue@apache.org>
Committed: Sat Nov 5 13:18:54 2016 -0700

----------------------------------------------------------------------
 CHANGES.txt                                            |  3 +++
 .../main/java/org/apache/avro/SchemaCompatibility.java | 13 +++++++++++--
 .../java/org/apache/avro/TestSchemaCompatibility.java  |  8 +++++---
 3 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/1b91c06e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0457922..4437aed 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -75,6 +75,9 @@ Trunk (not yet released)
     AVRO-1860: Java: Field#DefaultVal() returns Ints for Long fields.
     (Gabor Szadovszky via cutting)
 
+    AVRO-1929: Java: SchemaCompatibility fails to recognize
+    string<->bytes promotion.  (Anders Sundelin via cutting)
+
 Avro 1.8.1 (14 May 2016)
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/avro/blob/1b91c06e/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/1b91c06e/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 9b8cde1..5ff7225 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