avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1651831 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/Schema.java lang/java/avro/src/test/java/org/apache/avro/TestSchema.java
Date Wed, 14 Jan 2015 21:16:57 GMT
Author: cutting
Date: Wed Jan 14 21:16:56 2015
New Revision: 1651831

URL: http://svn.apache.org/r1651831
Log:
AVRO-1628. Java: Add Schema#createUnion(Schema ...) convenience method.  Contributed by Clément
Mahtieu.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1651831&r1=1651830&r2=1651831&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Jan 14 21:16:56 2015
@@ -63,6 +63,9 @@ Trunk (not yet released)
     AVRO-1539. Java: Add FileSystem based FsInput constructor.
     (Allan Shoup via cutting)
 
+    AVRO-1628. Java: Add Schema#createUnion(Schema ...) convenience method.
+    (Clément Mahtieu via cutting)
+
   BUG FIXES
 
     AVRO-1553. Java: MapReduce never uses MapOutputValueSchema (tomwhite)

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java?rev=1651831&r1=1651830&r2=1651831&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/Schema.java Wed Jan 14 21:16:56
2015
@@ -174,6 +174,11 @@ public abstract class Schema extends Jso
   }
 
   /** Create a union schema. */
+  public static Schema createUnion(Schema... types) {
+    return createUnion(new LockableArrayList<Schema>(types));
+  }
+
+  /** Create a union schema. */
   public static Schema createFixed(String name, String doc, String space,
       int size) {
     return new FixedSchema(new Name(name, space), doc, size);
@@ -1524,6 +1529,11 @@ public abstract class Schema extends Jso
       super(types);
     }
 
+    public LockableArrayList(E... types) {
+      super(types.length);
+      Collections.addAll(this, types);
+    }
+
     public List<E> lock() {
       locked = true;
       return this;

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java?rev=1651831&r1=1651830&r2=1651831&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestSchema.java Wed Jan 14 21:16:56
2015
@@ -64,4 +64,15 @@ public class TestSchema {
       assertTrue(are.getMessage().contains("Duplicate field field_name in record RecordName"));
     }
   }
+
+  @Test
+  public void testCreateUnionVarargs() {
+    List<Schema> types = new ArrayList<Schema>();
+    types.add(Schema.create(Type.NULL));
+    types.add(Schema.create(Type.LONG));
+    Schema expected = Schema.createUnion(types);
+
+    Schema schema = Schema.createUnion(Schema.create(Type.NULL), Schema.create(Type.LONG));
+    assertEquals(expected, schema);
+  }
 }



Mime
View raw message