avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1241662 - in /avro/trunk: ./ lang/java/avro/src/main/java/org/apache/avro/data/ lang/java/avro/src/main/java/org/apache/avro/generic/ lang/java/avro/src/main/java/org/apache/avro/reflect/ lang/java/avro/src/main/java/org/apache/avro/specif...
Date Tue, 07 Feb 2012 22:15:41 GMT
Author: cutting
Date: Tue Feb  7 22:15:41 2012
New Revision: 1241662

URL: http://svn.apache.org/viewvc?rev=1241662&view=rev
Log:
AVRO-1020. Java: Fix builder API to correctly handle default values for enums.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java
    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/reflect/ReflectData.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/specific/SpecificData.java
    avro/trunk/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
    avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
    avro/trunk/share/test/schemas/social.avdl

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1241662&r1=1241661&r2=1241662&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Feb  7 22:15:41 2012
@@ -102,6 +102,9 @@ Avro 1.6.2 (unreleased)
     AVRO-996. Java: SpecificRecord builder pattern object copy fails 
     with unions in some cases. (scottcarey and jbaldassari)
 
+    AVRO-1020. Java: Fix builder API to correctly handle default
+    values for enums.  (cutting)
+
 Avro 1.6.1 (8 November 2011)
 
   INCOMPATIBLE CHANGES

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java?rev=1241662&r1=1241661&r2=1241662&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/data/RecordBuilderBase.java Tue
Feb  7 22:15:41 2012
@@ -28,7 +28,6 @@ import org.apache.avro.Schema;
 import org.apache.avro.Schema.Field;
 import org.apache.avro.Schema.Type;
 import org.apache.avro.generic.GenericData;
-import org.apache.avro.generic.GenericDatumReader;
 import org.apache.avro.generic.IndexedRecord;
 import org.apache.avro.io.BinaryDecoder;
 import org.apache.avro.io.BinaryEncoder;
@@ -179,7 +178,7 @@ public abstract class RecordBuilderBase<
       encoder.flush();
       decoder = DecoderFactory.get().binaryDecoder(
           baos.toByteArray(), decoder);
-      defaultValue = new GenericDatumReader(
+      defaultValue = data.createDatumReader(
           field.schema()).read(null, decoder);
       defaultSchemaValues.putIfAbsent(field.pos(), defaultValue);
     }

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=1241662&r1=1241661&r2=1241662&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 Tue Feb
 7 22:15:41 2012
@@ -33,6 +33,7 @@ import org.apache.avro.Schema.Field;
 import org.apache.avro.Schema.Type;
 import org.apache.avro.UnresolvedUnionException;
 import org.apache.avro.io.BinaryData;
+import org.apache.avro.io.DatumReader;
 import org.apache.avro.util.Utf8;
 
 /** Utilities for generic Java data. */
@@ -299,6 +300,11 @@ public class GenericData {
     public String toString() { return symbol; }
   }
 
+  /** Returns a {@link DatumReader} for this kind of data. */
+  public DatumReader createDatumReader(Schema schema) {
+    return new GenericDatumReader(schema, schema, this);
+  }
+
   /** Returns true if a Java datum matches a schema. */
   public boolean validate(Schema schema, Object datum) {
     switch (schema.getType()) {

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java?rev=1241662&r1=1241661&r2=1241662&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java Tue Feb
 7 22:15:41 2012
@@ -46,6 +46,7 @@ import org.apache.avro.generic.GenericCo
 import org.apache.avro.specific.SpecificData;
 import org.apache.avro.specific.FixedSize;
 import org.apache.avro.io.BinaryData;
+import org.apache.avro.io.DatumReader;
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.node.NullNode;
 
@@ -79,6 +80,11 @@ public class ReflectData extends Specifi
   public static ReflectData get() { return INSTANCE; }
 
   @Override
+  public DatumReader createDatumReader(Schema schema) {
+    return new ReflectDatumReader(schema, schema, this);
+  }
+
+  @Override
   public void setField(Object record, String name, int position, Object o) {
     if (record instanceof IndexedRecord) {
       super.setField(record, name, position, o);

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=1241662&r1=1241661&r2=1241662&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 Tue
Feb  7 22:15:41 2012
@@ -33,6 +33,7 @@ import org.apache.avro.AvroRuntimeExcept
 import org.apache.avro.AvroTypeException;
 import org.apache.avro.Schema.Type;
 import org.apache.avro.generic.GenericData;
+import org.apache.avro.io.DatumReader;
 
 /** Utilities for generated Java classes and interfaces. */
 public class SpecificData extends GenericData {
@@ -54,6 +55,11 @@ public class SpecificData extends Generi
     this.classLoader = classLoader;
   }
   
+  @Override
+  public DatumReader createDatumReader(Schema schema) {
+    return new SpecificDatumReader(schema, schema, this);
+  }
+
   /** Return the singleton instance. */
   public static SpecificData get() { return INSTANCE; }
 

Modified: avro/trunk/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java?rev=1241662&r1=1241661&r2=1241662&view=diff
==============================================================================
--- avro/trunk/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
(original)
+++ avro/trunk/lang/java/protobuf/src/main/java/org/apache/avro/protobuf/ProtobufData.java
Tue Feb  7 22:15:41 2012
@@ -31,6 +31,7 @@ import org.apache.avro.Schema;
 import org.apache.avro.Schema.Field;
 import org.apache.avro.generic.GenericData;
 import org.apache.avro.specific.SpecificData;
+import org.apache.avro.io.DatumReader;
 
 import com.google.protobuf.ByteString;
 import com.google.protobuf.Message;
@@ -61,6 +62,11 @@ public class ProtobufData extends Generi
   public static ProtobufData get() { return INSTANCE; }
 
   @Override
+  public DatumReader createDatumReader(Schema schema) {
+    return new ProtobufDatumReader(schema, schema, this);
+  }
+
+  @Override
   public void setField(Object r, String n, int pos, Object o) {
     setField(r, n, pos, o, getRecordState(r, getSchema(r.getClass())));
   }

Modified: avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java?rev=1241662&r1=1241661&r2=1241662&view=diff
==============================================================================
--- avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java (original)
+++ avro/trunk/lang/java/thrift/src/main/java/org/apache/avro/thrift/ThriftData.java Tue Feb
 7 22:15:41 2012
@@ -29,6 +29,7 @@ import org.apache.avro.AvroRuntimeExcept
 import org.apache.avro.Schema.Field;
 import org.apache.avro.generic.GenericData;
 import org.apache.avro.specific.SpecificData;
+import org.apache.avro.io.DatumReader;
 
 import org.apache.thrift.TBase;
 import org.apache.thrift.TEnum;
@@ -57,6 +58,11 @@ public class ThriftData extends GenericD
   public static ThriftData get() { return INSTANCE; }
 
   @Override
+  public DatumReader createDatumReader(Schema schema) {
+    return new ThriftDatumReader(schema, schema, this);
+  }
+
+  @Override
   public void setField(Object r, String n, int pos, Object o) {
     setField(r, n, pos, o, getRecordState(r, getSchema(r.getClass())));
   }

Modified: avro/trunk/share/test/schemas/social.avdl
URL: http://svn.apache.org/viewvc/avro/trunk/share/test/schemas/social.avdl?rev=1241662&r1=1241661&r2=1241662&view=diff
==============================================================================
--- avro/trunk/share/test/schemas/social.avdl (original)
+++ avro/trunk/share/test/schemas/social.avdl Tue Feb  7 22:15:41 2012
@@ -19,6 +19,8 @@
 @version("1.0.5")
 @namespace("org.apache.avro.ipc.specific")
 protocol Social {
+  enum PrivacyType { FRIENDS, FRIENDS_OF_FRIENDS, PUBLIC, CUSTOM } 
+  
   record Person {
     string name;
     int year_of_birth;
@@ -26,5 +28,6 @@ protocol Social {
     string state;
     array<Person> friends = [];
     array<string> languages = [ "English" , "Java" ];
+    PrivacyType defaultPrivacy = "FRIENDS";
   }
 } 



Mime
View raw message