crunch-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwi...@apache.org
Subject crunch git commit: CRUNCH-548: Have the AvroReflectDeepCopier use the class of the source object when constructing new instances instead of the target class (which might be an interface/abstract class)
Date Thu, 23 Jul 2015 17:04:41 GMT
Repository: crunch
Updated Branches:
  refs/heads/master de1553e73 -> 9146d10da


CRUNCH-548: Have the AvroReflectDeepCopier use the class of the source object when constructing
new instances instead of the target class (which might be an interface/abstract class)


Project: http://git-wip-us.apache.org/repos/asf/crunch/repo
Commit: http://git-wip-us.apache.org/repos/asf/crunch/commit/9146d10d
Tree: http://git-wip-us.apache.org/repos/asf/crunch/tree/9146d10d
Diff: http://git-wip-us.apache.org/repos/asf/crunch/diff/9146d10d

Branch: refs/heads/master
Commit: 9146d10dae2452e699ac9506f5bbe754902dfc32
Parents: de1553e
Author: Josh Wills <jwills@apache.org>
Authored: Wed Jul 22 10:45:19 2015 -0700
Committer: Josh Wills <jwills@apache.org>
Committed: Thu Jul 23 09:49:51 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/crunch/types/avro/AvroDeepCopier.java    | 8 ++------
 .../src/main/java/org/apache/crunch/types/avro/Avros.java    | 2 +-
 .../org/apache/crunch/types/avro/AvroDeepCopierTest.java     | 4 ++--
 3 files changed, 5 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/crunch/blob/9146d10d/crunch-core/src/main/java/org/apache/crunch/types/avro/AvroDeepCopier.java
----------------------------------------------------------------------
diff --git a/crunch-core/src/main/java/org/apache/crunch/types/avro/AvroDeepCopier.java b/crunch-core/src/main/java/org/apache/crunch/types/avro/AvroDeepCopier.java
index 5000f8d..e6b878a 100644
--- a/crunch-core/src/main/java/org/apache/crunch/types/avro/AvroDeepCopier.java
+++ b/crunch-core/src/main/java/org/apache/crunch/types/avro/AvroDeepCopier.java
@@ -103,11 +103,9 @@ abstract class AvroDeepCopier<T> implements DeepCopier<T>,
Serializable {
     private transient DatumWriter<T> datumWriter;
     private transient BinaryEncoder binaryEncoder;
     private transient BinaryDecoder binaryDecoder;
-    private final Class<T> valueClass;
 
-    public AvroReflectDeepCopier(Class<T> valueClass, Schema schema) {
+    public AvroReflectDeepCopier(Schema schema) {
       super(schema);
-      this.valueClass = valueClass;
     }
 
     protected DatumReader<T> createDatumReader(Configuration conf) {
@@ -126,11 +124,9 @@ abstract class AvroDeepCopier<T> implements DeepCopier<T>,
Serializable {
      */
     @Override
     public T deepCopy(T source) {
-
       if (source == null) {
         return null;
       }
-
       if (datumReader == null) {
         datumReader = createDatumReader(conf);
       }
@@ -139,7 +135,7 @@ abstract class AvroDeepCopier<T> implements DeepCopier<T>,
Serializable {
       }
       ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
       binaryEncoder = EncoderFactory.get().binaryEncoder(byteOutStream, binaryEncoder);
-      T target = createNewInstance(valueClass);
+      T target = createNewInstance((Class<T>) source.getClass());
       try {
         datumWriter.write(source, binaryEncoder);
         binaryEncoder.flush();

http://git-wip-us.apache.org/repos/asf/crunch/blob/9146d10d/crunch-core/src/main/java/org/apache/crunch/types/avro/Avros.java
----------------------------------------------------------------------
diff --git a/crunch-core/src/main/java/org/apache/crunch/types/avro/Avros.java b/crunch-core/src/main/java/org/apache/crunch/types/avro/Avros.java
index 0c602d4..3642769 100644
--- a/crunch-core/src/main/java/org/apache/crunch/types/avro/Avros.java
+++ b/crunch-core/src/main/java/org/apache/crunch/types/avro/Avros.java
@@ -278,7 +278,7 @@ public class Avros {
 
   public static final <T> AvroType<T> reflects(Class<T> clazz, Schema schema)
{
     AvroMode.registerSpecificClassLoaderInternal(clazz.getClassLoader());
-    return new AvroType<T>(clazz, schema, new AvroDeepCopier.AvroReflectDeepCopier<T>(clazz,
schema));
+    return new AvroType<T>(clazz, schema, new AvroDeepCopier.AvroReflectDeepCopier<T>(schema));
   }
 
   private static class BytesToWritableMapFn<T extends Writable> extends MapFn<Object,
T> {

http://git-wip-us.apache.org/repos/asf/crunch/blob/9146d10d/crunch-core/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
----------------------------------------------------------------------
diff --git a/crunch-core/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
b/crunch-core/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
index 4f5cb75..e3717c8 100644
--- a/crunch-core/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
+++ b/crunch-core/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
@@ -82,7 +82,7 @@ public class AvroDeepCopierTest {
     person.setSiblingnames(Lists.<String>newArrayList());
 
     AvroDeepCopier<ReflectedPerson> avroDeepCopier = new AvroDeepCopier.AvroReflectDeepCopier<ReflectedPerson>(
-        ReflectedPerson.class, Avros.reflects(ReflectedPerson.class).getSchema());
+        Avros.reflects(ReflectedPerson.class).getSchema());
     avroDeepCopier.initialize(new Configuration());
 
     ReflectedPerson deepCopyPerson = avroDeepCopier.deepCopy(person);
@@ -120,7 +120,7 @@ public class AvroDeepCopierTest {
   @Test
   public void testDeepCopyReflect_Null() {
     AvroDeepCopier<ReflectedPerson> avroDeepCopier = new AvroDeepCopier.AvroReflectDeepCopier<ReflectedPerson>(
-        ReflectedPerson.class, Avros.reflects(ReflectedPerson.class).getSchema());
+        Avros.reflects(ReflectedPerson.class).getSchema());
     avroDeepCopier.initialize(new Configuration());
 
     assertNull(avroDeepCopier.deepCopy(null));


Mime
View raw message