avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject avro git commit: AVRO-1883: Java: Fix incompatible schema detection nested in unions. Contributed by Yibing Shi.
Date Fri, 27 Oct 2017 14:46:47 GMT
Repository: avro
Updated Branches:
  refs/heads/branch-1.7 59f8a8c40 -> 011a85653


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

(cherry picked from commit 968550da18708c76fd04c13722d996461aa23cb7)


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

Branch: refs/heads/branch-1.7
Commit: 011a856536a6d255dc6ecd077f5246ee95c0ff1c
Parents: 59f8a8c
Author: Ryan Blue <blue@apache.org>
Authored: Sun Sep 4 15:15:24 2016 -0700
Committer: Sean Busbey <busbey@cloudera.com>
Committed: Fri Oct 27 09:19:13 2017 -0500

----------------------------------------------------------------------
 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/011a8565/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b082a60..9f24bbd 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -72,6 +72,9 @@ Trunk (not yet released)
 
     AVRO-1656. Fix 'How to Contribute' link. (Benjamin Clauss via blue)
 
+    AVRO-1883: Java: Fix incompatible schema detection nested in unions.
+    (Yibing Shi via blue)
+
 Avro 1.7.7 (23 July 2014)
 
   NEW FEATURES

http://git-wip-us.apache.org/repos/asf/avro/blob/011a8565/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 08a9d14..92b2dab 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
@@ -361,7 +361,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/011a8565/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 0d56abb..9e25767 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.junit.Assert;
 import org.junit.Test;
@@ -119,6 +120,22 @@ public class TestSchemaValidation {
     builder.strategy(null).validateAll();
   }
 
+  @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