avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1556982 - in /avro/trunk: CHANGES.txt lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
Date Thu, 09 Jan 2014 23:34:08 GMT
Author: cutting
Date: Thu Jan  9 23:34:08 2014
New Revision: 1556982

URL: http://svn.apache.org/r1556982
Log:
AVRO-1433. Java: Fix compiler to not drop aliases when StringType is String.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1556982&r1=1556981&r2=1556982&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Thu Jan  9 23:34:08 2014
@@ -119,6 +119,9 @@ Trunk (not yet released)
 
     AVRO-1424. ValidatingDecoder hangs on large schema (thiru)
 
+    AVRO-1433. Java: Fix compiler to not drop aliases when StringType
+    is String. (cutting)
+
 Avro 1.7.5 (12 August 2013)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java?rev=1556982&r1=1556981&r2=1556982&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
(original)
+++ avro/trunk/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
Thu Jan  9 23:34:08 2014
@@ -441,6 +441,8 @@ public class SpecificCompiler {
     case RECORD:
       result =
         Schema.createRecord(s.getFullName(), s.getDoc(), null, s.isError());
+      for (String alias : s.getAliases())
+        result.addAlias(alias, null);             // copy aliases
       seen.put(s, result);
       List<Field> newFields = new ArrayList<Field>();
       for (Field f : s.getFields()) {
@@ -449,6 +451,8 @@ public class SpecificCompiler {
           new Field(f.name(), fSchema, f.doc(), f.defaultValue(), f.order());
         for (Map.Entry<String,JsonNode> p : f.getJsonProps().entrySet())
           newF.addProp(p.getKey(), p.getValue()); // copy props
+        for (String a : f.aliases())
+          newF.addAlias(a);                       // copy aliases
         newFields.add(newF);
       }
       result.setFields(newFields);

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java?rev=1556982&r1=1556981&r2=1556982&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
(original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
Thu Jan  9 23:34:08 2014
@@ -43,6 +43,7 @@ import org.apache.avro.Schema.Type;
 import org.apache.avro.TestProtocolParsing;
 import org.apache.avro.TestSchema;
 import org.apache.avro.TestAnnotation;
+import org.apache.avro.generic.GenericData.StringType;
 
 import org.apache.avro.test.Simple;
 import org.apache.avro.test.TestRecord;
@@ -672,6 +673,21 @@ public class TestSpecificCompiler {
                   .getAnnotation(TestAnnotation.class));
   }
 
+  @Test
+  public void testAliases() throws IOException {
+    Schema s = Schema.parse
+      ("{\"name\":\"X\",\"type\":\"record\",\"aliases\":[\"Y\"],\"fields\":["
+       +"{\"name\":\"f\",\"type\":\"int\",\"aliases\":[\"g\"]}]}");
+    SpecificCompiler compiler = new SpecificCompiler(s);
+    compiler.setStringType(StringType.valueOf("String"));
+    Collection<OutputFile> outputs = compiler.compile();
+    assertEquals(1, outputs.size());
+    OutputFile o = outputs.iterator().next();
+    assertEquals(o.path, "X.java");
+    assertTrue(o.contents.contains("[\\\"Y\\\"]"));
+    assertTrue(o.contents.contains("[\\\"g\\\"]"));
+  }
+
   /**
    * Checks that a schema passes through the SpecificCompiler, and,
    * optionally, uses the system's Java compiler to check



Mime
View raw message