avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1480374 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/generic/ lang/java/avro/src/main/java/org/apache/avro/specific/ lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/ lang/java/trevni/avro/src/test/cases/enum/
Date Wed, 08 May 2013 17:35:51 GMT
Author: cutting
Date: Wed May  8 17:35:51 2013
New Revision: 1480374

URL: http://svn.apache.org/r1480374
Log:
Java: Fix Trevni to correctly read unions and specific enums.

Added:
    avro/trunk/lang/java/trevni/avro/src/test/cases/enum/
    avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.avsc
    avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.json
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
    avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1480374&r1=1480373&r2=1480374&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed May  8 17:35:51 2013
@@ -67,6 +67,9 @@ Trunk (not yet released)
     AVRO-1306. Java mapred: Fix incorrect documentation for combiners.
     (Mina Naguib via martinkl)
 
+    AVRO-1320. Java: Fix Trevni to correctly read unions and specific enums.
+    (cutting)
+
 Avro 1.7.4 (22 February 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java?rev=1480374&r1=1480373&r2=1480374&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java Wed May
 8 17:35:51 2013
@@ -971,6 +971,12 @@ public class GenericData {
     return fixed;
   }
   
+  /** Called to create an enum value. May be overridden for alternate enum
+   * representations.  By default, returns a GenericEnumSymbol. */
+  public Object createEnum(String symbol, Schema schema) {
+    return new EnumSymbol(schema, symbol);
+  }
+
   /**
    * Called to create new record instances. Subclasses may override to use a
    * different record implementation. The returned instance must conform to the

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java?rev=1480374&r1=1480373&r2=1480374&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
Wed May  8 17:35:51 2013
@@ -202,7 +202,7 @@ public class GenericDatumReader<D> imple
   /** Called to create an enum value. May be overridden for alternate enum
    * representations.  By default, returns a GenericEnumSymbol. */
   protected Object createEnum(String symbol, Schema schema) {
-    return new GenericData.EnumSymbol(schema, symbol);
+    return data.createEnum(symbol, schema);
   }
 
   /** Called to read an array instance.  May be overridden for alternate array

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java?rev=1480374&r1=1480373&r2=1480374&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java Wed
May  8 17:35:51 2013
@@ -93,6 +93,13 @@ public class SpecificData extends Generi
   }
 
   @Override
+  public Object createEnum(String symbol, Schema schema) {
+    Class c = getClass(schema);
+    if (c == null) return super.createEnum(symbol, schema); // punt to generic
+    return Enum.valueOf(c, symbol);
+  }
+
+  @Override
   protected Schema getEnumSchema(Object datum) {
     return (datum instanceof Enum)
       ? getSchema(datum.getClass())

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java?rev=1480374&r1=1480373&r2=1480374&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
(original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificDatumReader.java
Wed May  8 17:35:51 2013
@@ -72,14 +72,6 @@ public class SpecificDatumReader<T> exte
     super.setSchema(actual);
   }
 
-  @Override
-  @SuppressWarnings("unchecked")
-  protected Object createEnum(String symbol, Schema schema) {
-    Class c = getSpecificData().getClass(schema);
-    if (c == null) return super.createEnum(symbol, schema); // punt to generic
-    return Enum.valueOf(c, symbol);
-  }
-
   @Override protected Class findStringClass(Schema schema) {
     Class stringClass = null;
     switch (schema.getType()) {

Modified: avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java?rev=1480374&r1=1480373&r2=1480374&view=diff
==============================================================================
--- avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java
(original)
+++ avro/trunk/lang/java/trevni/avro/src/main/java/org/apache/trevni/avro/AvroColumnReader.java
Wed May  8 17:35:51 2013
@@ -238,7 +238,7 @@ public class AvroColumnReader<D>
       for (Schema branch : s.getTypes()) {
         if (branch.getType() == Schema.Type.NULL) continue;
         if (values[column].nextLength() == 1) {
-          value = nextValue(s, column);
+          value = nextValue(branch, column);
           column++;
           if (!isSimple(branch))
             value = read(branch);
@@ -257,9 +257,9 @@ public class AvroColumnReader<D>
     
     switch (s.getType()) {
     case ENUM:
-      return new GenericData.EnumSymbol(s, s.getEnumSymbols().get((Integer)v));
+      return model.createEnum(s.getEnumSymbols().get((Integer)v), s);
     case FIXED:
-      return new GenericData.Fixed(s, ((ByteBuffer)v).array());
+      return model.createFixed(null, ((ByteBuffer)v).array(), s);
     }
 
     return v;

Added: avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.avsc
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.avsc?rev=1480374&view=auto
==============================================================================
--- avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.avsc (added)
+++ avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.avsc Wed May  8 17:35:51 2013
@@ -0,0 +1,17 @@
+{
+    "type": "record",
+    "name": "Test",
+    "fields": [
+        {
+            "name": "kind",
+            "type": [
+                "null",
+                {
+                    "name": "Kind",
+                    "type": "enum",
+                    "symbols": ["X", "Y", "Z"]
+                }
+            ]
+        }
+    ]
+}

Added: avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.json
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.json?rev=1480374&view=auto
==============================================================================
--- avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.json (added)
+++ avro/trunk/lang/java/trevni/avro/src/test/cases/enum/input.json Wed May  8 17:35:51 2013
@@ -0,0 +1,4 @@
+{"kind":null}
+{"kind":{"Kind":"X"}}
+{"kind":{"Kind":"Y"}}
+{"kind":{"Kind":"Z"}}



Mime
View raw message