avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject avro git commit: AVRO-1883: Java: Fix incompatible schema detection nested in unions. Contributed by Yibing Shi.
Date Sun, 04 Sep 2016 22:19:12 GMT
Repository: avro
Updated Branches:
  refs/heads/master 64f898c43 -> 5acae5e10


AVRO-1883: Java: Fix incompatible schema detection nested in unions. Contributed by Yibing
Shi.


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

Branch: refs/heads/master
Commit: 5acae5e10ee5d9d7d98b208e29a930f1e66f40ae
Parents: 64f898c
Author: Ryan Blue <blue@apache.org>
Authored: Sun Sep 4 15:15:24 2016 -0700
Committer: Ryan Blue <blue@apache.org>
Committed: Sun Sep 4 15:19:01 2016 -0700

----------------------------------------------------------------------
 CHANGES.txt                                        |  3 +++
 .../java/org/apache/avro/io/parsing/Symbol.java    | 10 +++++++++-
 .../java/org/apache/avro/TestSchemaValidation.java | 17 +++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/5acae5e1/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4e28878..85a3272 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -45,6 +45,9 @@ Trunk (not yet released)
     AVRO-1874: Py3: Use recommended module-level logging.
     (Torgeir Børresen via blue)
 
+    AVRO-1883: Java: Fix incompatible schema detection nested in unions.
+    (Yibing Shi via blue)
+
 Avro 1.8.1 (14 May 2016)
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/avro/blob/5acae5e1/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
index 178aa0b..f33c292 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/io/parsing/Symbol.java
@@ -375,7 +375,15 @@ public abstract class Symbol {
     case EXPLICIT_ACTION:
       return false;
     case IMPLICIT_ACTION:
-      return symbol instanceof ErrorAction;
+      if (symbol instanceof ErrorAction) {
+        return true;
+      }
+
+      if (symbol instanceof UnionAdjustAction) {
+        return hasErrors(((UnionAdjustAction) symbol).symToParse);
+      }
+
+      return false;
     case REPEATER:
       Repeater r = (Repeater) symbol;
       return hasErrors(r.end) || hasErrors(symbol, r.production);

http://git-wip-us.apache.org/repos/asf/avro/blob/5acae5e1/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java
index 0c0c166..838dc91 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaValidation.java
@@ -19,6 +19,7 @@
 package org.apache.avro;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 
 import org.apache.avro.reflect.ReflectData;
 import org.junit.Assert;
@@ -162,6 +163,22 @@ public class TestSchemaValidation {
         circleSchemaDifferentNames, ReflectData.AllowNull.get().getSchema(Circle.class));
   }
 
+  @Test
+  public void testUnionWithIncompatibleElements() throws SchemaValidationException {
+    Schema union1 = Schema.createUnion(Arrays.asList(rec));
+    Schema union2 = Schema.createUnion(Arrays.asList(rec4));
+    testValidatorFails(builder.canReadStrategy().validateAll(),
+        union2, union1);
+  }
+
+  @Test
+  public void testUnionWithCompatibleElements() throws SchemaValidationException {
+    Schema union1 = Schema.createUnion(Arrays.asList(rec));
+    Schema union2 = Schema.createUnion(Arrays.asList(rec3));
+    testValidatorPasses(builder.canReadStrategy().validateAll(),
+        union2, union1);
+  }
+
   private void testValidatorPasses(SchemaValidator validator,
       Schema schema, Schema... prev) throws SchemaValidationException {
     ArrayList<Schema> prior = new ArrayList<Schema>();


Mime
View raw message