avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1241665 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/Schema.java lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
Date Tue, 07 Feb 2012 22:22:16 GMT
Author: cutting
Date: Tue Feb  7 22:22:16 2012
New Revision: 1241665

URL: http://svn.apache.org/viewvc?rev=1241665&view=rev
Log:
AVRO-1016. Java: Add Field#getAliases() method to better permit copying of schemas.

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

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1241665&r1=1241664&r2=1241665&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Feb  7 22:22:16 2012
@@ -48,6 +48,9 @@ Avro 1.6.2 (unreleased)
 
     AVRO-1011. Improve POM structure. (Lars Francke via scottcarey) 
 
+    AVRO-1016. Java: Add Field#getAliases() method to better permit
+    copying of schemas. (cutting)
+
   BUG FIXES
 
     AVRO-962. Java: Fix Maven plugin to support string type override.

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=1241665&r1=1241664&r2=1241665&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 Tue Feb  7 22:22:16
2012
@@ -438,6 +438,12 @@ public abstract class Schema {
         this.aliases = new LinkedHashSet<String>();
       aliases.add(alias);
     }
+    /** Return the defined aliases as an unmodifieable Set. */
+    public Set<String> aliases() {
+      if (aliases == null)
+        return Collections.emptySet();
+      return Collections.unmodifiableSet(aliases);
+    }
     public boolean equals(Object other) {
       if (other == this) return true;
       if (!(other instanceof Field)) return false;
@@ -554,7 +560,7 @@ public abstract class Schema {
       return super.computeHash() + name.hashCode();
     }
     public void aliasesToJson(JsonGenerator gen) throws IOException {
-      if (aliases == null) return;
+      if (aliases == null || aliases.size() == 0) return;
       gen.writeFieldName("aliases");
       gen.writeStartArray();
       for (Name alias : aliases)
@@ -686,7 +692,7 @@ public abstract class Schema {
         }
         if (f.order() != Field.Order.ASCENDING)
           gen.writeStringField("order", f.order().name);
-        if (f.aliases != null) {
+        if (f.aliases != null && f.aliases.size() != 0) {
           gen.writeFieldName("aliases");
           gen.writeStartArray();
           for (String alias : f.aliases)

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java?rev=1241665&r1=1241664&r2=1241665&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/TestSchema.java Tue Feb  7 22:22:16
2012
@@ -33,6 +33,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Collection;
+import java.util.Collections;
 
 import org.codehaus.jackson.JsonNode;
 
@@ -549,6 +550,12 @@ public class TestSchema {
       +"{\"name\":\"h\",\"type\":\"int\"}]}";
     Schema s1 = Schema.parse(t1);
     Schema s2 = Schema.parse(t2);
+
+    assertEquals(s1.getAliases(), Collections.emptySet());
+    assertEquals(s1.getField("f").aliases(), Collections.emptySet());
+    assertEquals(s2.getAliases(), Collections.singleton("a.b"));
+    assertEquals(s2.getField("g").aliases(), Collections.singleton("f"));
+
     Schema s3 = Schema.applyAliases(s1,s2);
     assertFalse(s2 == s3);
     assertEquals(s2, s3);



Mime
View raw message