avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anders Sundelin (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (AVRO-1929) SchemaCompatibility fails to recognize string<->bytes promotion
Date Tue, 04 Oct 2016 14:00:28 GMT

     [ https://issues.apache.org/jira/browse/AVRO-1929?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Anders Sundelin updated AVRO-1929:
----------------------------------
    Status: Patch Available  (was: Open)

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;
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),

> SchemaCompatibility fails to recognize string<->bytes promotion
> ---------------------------------------------------------------
>
>                 Key: AVRO-1929
>                 URL: https://issues.apache.org/jira/browse/AVRO-1929
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.1, 1.8.0, 1.7.7, 1.9.0
>         Environment: Any Java env
>            Reporter: Anders Sundelin
>            Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The class SchemaCompatibility fails to realize the change made as of 
> AVRO-1553, where string-to/from-bytes promotions were allowed (according to docs, this
was integrated into 1.7.7)
> The submitted fix corrects this (also updating the relevant unit test)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message