incubator-crunch-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwi...@apache.org
Subject [3/9] git commit: Crunch changes to support running with older versions of Avro
Date Wed, 22 Aug 2012 06:26:48 GMT
Crunch changes to support running with older versions of Avro

Signed-off-by: Josh Wills <jwills@cloudera.com>


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

Branch: refs/heads/master
Commit: b8891e5479f129ce2321c64679ae6621a3992a38
Parents: 1181987
Author: jwills <jwills@apache.org>
Authored: Fri Aug 17 23:08:42 2012 -0700
Committer: Josh Wills <jwills@cloudera.com>
Committed: Tue Aug 21 18:54:29 2012 -0700

----------------------------------------------------------------------
 .../crunch/io/avro/AvroFileSourceTargetIT.java     |    6 +-
 .../it/java/org/apache/crunch/lib/AggregateIT.java |    6 +-
 .../java/org/apache/crunch/lib/AvroTypeSortIT.java |   10 ++--
 .../crunch/lib/join/MultiAvroSchemaJoinIT.java     |   28 +++++-----
 .../org/apache/crunch/types/avro/AvroType.java     |   19 +++++++-
 .../java/org/apache/crunch/types/avro/Avros.java   |   10 ++++
 .../crunch/io/avro/AvroFileReaderFactoryTest.java  |    6 +-
 .../crunch/types/CollectionDeepCopierTest.java     |    6 +-
 .../apache/crunch/types/TupleDeepCopierTest.java   |    6 +-
 .../crunch/types/avro/AvroDeepCopierTest.java      |   36 ++++++++++----
 .../types/avro/AvroGroupedTableTypeTest.java       |    8 ++--
 .../crunch/types/avro/AvroTableTypeTest.java       |    8 ++--
 .../org/apache/crunch/types/avro/AvroTypeTest.java |   38 +++++++++++----
 .../org/apache/crunch/types/avro/AvrosTest.java    |   12 ++--
 14 files changed, 129 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/it/java/org/apache/crunch/io/avro/AvroFileSourceTargetIT.java
----------------------------------------------------------------------
diff --git a/crunch/src/it/java/org/apache/crunch/io/avro/AvroFileSourceTargetIT.java b/crunch/src/it/java/org/apache/crunch/io/avro/AvroFileSourceTargetIT.java
index 2e5a3bf..c310d94 100644
--- a/crunch/src/it/java/org/apache/crunch/io/avro/AvroFileSourceTargetIT.java
+++ b/crunch/src/it/java/org/apache/crunch/io/avro/AvroFileSourceTargetIT.java
@@ -96,13 +96,13 @@ public class AvroFileSourceTargetIT implements Serializable {
     List<Person> personList = Lists.newArrayList(genericCollection.materialize());
 
     Person expectedPerson = new Person();
-    expectedPerson.setName("John Doe");
-    expectedPerson.setAge(42);
+    expectedPerson.name = "John Doe";
+    expectedPerson.age = 42;
 
     List<CharSequence> siblingNames = Lists.newArrayList();
     siblingNames.add("Jimmy");
     siblingNames.add("Jane");
-    expectedPerson.setSiblingnames(siblingNames);
+    expectedPerson.siblingnames = siblingNames;
 
     assertEquals(Lists.newArrayList(expectedPerson), Lists.newArrayList(personList));
   }

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/it/java/org/apache/crunch/lib/AggregateIT.java
----------------------------------------------------------------------
diff --git a/crunch/src/it/java/org/apache/crunch/lib/AggregateIT.java b/crunch/src/it/java/org/apache/crunch/lib/AggregateIT.java
index 4f47d8f..5d40772 100644
--- a/crunch/src/it/java/org/apache/crunch/lib/AggregateIT.java
+++ b/crunch/src/it/java/org/apache/crunch/lib/AggregateIT.java
@@ -180,9 +180,9 @@ public class AggregateIT {
     @Override
     public Pair<Integer, Employee> map(String input) {
       Employee emp = new Employee();
-      emp.setName(input);
-      emp.setSalary(0);
-      emp.setDepartment("");
+      emp.name = input;
+      emp.salary = 0;
+      emp.department = "";
       return Pair.of(1, emp);
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/it/java/org/apache/crunch/lib/AvroTypeSortIT.java
----------------------------------------------------------------------
diff --git a/crunch/src/it/java/org/apache/crunch/lib/AvroTypeSortIT.java b/crunch/src/it/java/org/apache/crunch/lib/AvroTypeSortIT.java
index a7b8e9b..a832a5d 100644
--- a/crunch/src/it/java/org/apache/crunch/lib/AvroTypeSortIT.java
+++ b/crunch/src/it/java/org/apache/crunch/lib/AvroTypeSortIT.java
@@ -83,7 +83,7 @@ public class AvroTypeSortIT implements Serializable {
 
       @Override
       public String map(Person input) {
-        return input.getName().toString();
+        return input.name.toString();
       }
     };
 
@@ -102,7 +102,7 @@ public class AvroTypeSortIT implements Serializable {
 
       @Override
       public Integer map(Person input) {
-        return input.getAge();
+        return input.age;
       }
     };
 
@@ -135,10 +135,10 @@ public class AvroTypeSortIT implements Serializable {
   private Person createPerson(String name, int age) throws IOException {
 
     Person person = new Person();
-    person.setAge(age);
-    person.setName(name);
+    person.age = age;
+    person.name = name;
     List<CharSequence> siblingNames = Lists.newArrayList();
-    person.setSiblingnames(siblingNames);
+    person.siblingnames = siblingNames;
 
     return person;
   }

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/it/java/org/apache/crunch/lib/join/MultiAvroSchemaJoinIT.java
----------------------------------------------------------------------
diff --git a/crunch/src/it/java/org/apache/crunch/lib/join/MultiAvroSchemaJoinIT.java b/crunch/src/it/java/org/apache/crunch/lib/join/MultiAvroSchemaJoinIT.java
index e9b2fa2..f1ca770 100644
--- a/crunch/src/it/java/org/apache/crunch/lib/join/MultiAvroSchemaJoinIT.java
+++ b/crunch/src/it/java/org/apache/crunch/lib/join/MultiAvroSchemaJoinIT.java
@@ -63,19 +63,19 @@ public class MultiAvroSchemaJoinIT {
     DataFileWriter<Person> pfw = new DataFileWriter<Person>(pdw);
     pfw.create(Person.SCHEMA$, personFile);
     Person p1 = new Person();
-    p1.setName("Josh");
-    p1.setAge(19);
-    p1.setSiblingnames(ImmutableList.<CharSequence> of("Kate", "Mike"));
+    p1.name = "Josh";
+    p1.age = 19;
+    p1.siblingnames = ImmutableList.<CharSequence> of("Kate", "Mike");
     pfw.append(p1);
     Person p2 = new Person();
-    p2.setName("Kate");
-    p2.setAge(17);
-    p2.setSiblingnames(ImmutableList.<CharSequence> of("Josh", "Mike"));
+    p2.name = "Kate";
+    p2.age = 17;;
+    p2.siblingnames = ImmutableList.<CharSequence> of("Josh", "Mike");
     pfw.append(p2);
     Person p3 = new Person();
-    p3.setName("Mike");
-    p3.setAge(12);
-    p3.setSiblingnames(ImmutableList.<CharSequence> of("Josh", "Kate"));
+    p3.name = "Mike";
+    p3.age = 12;
+    p3.siblingnames = ImmutableList.<CharSequence> of("Josh", "Kate");
     pfw.append(p3);
     pfw.close();
 
@@ -83,9 +83,9 @@ public class MultiAvroSchemaJoinIT {
     DataFileWriter<Employee> efw = new DataFileWriter<Employee>(edw);
     efw.create(Employee.SCHEMA$, employeeFile);
     Employee e1 = new Employee();
-    e1.setName("Kate");
-    e1.setSalary(100000);
-    e1.setDepartment("Marketing");
+    e1.name = "Kate";
+    e1.salary = 100000;
+    e1.department = "Marketing";
     efw.append(e1);
     efw.close();
   }
@@ -115,7 +115,7 @@ public class MultiAvroSchemaJoinIT {
         .join(employees.by(new NameFn<Employee>(), strings())).values().materialize();
     List<Pair<Person, Employee>> v = Lists.newArrayList(result);
     assertEquals(1, v.size());
-    assertEquals("Kate", v.get(0).first().getName().toString());
-    assertEquals("Kate", v.get(0).second().getName().toString());
+    assertEquals("Kate", v.get(0).first().name.toString());
+    assertEquals("Kate", v.get(0).second().name.toString());
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/main/java/org/apache/crunch/types/avro/AvroType.java
----------------------------------------------------------------------
diff --git a/crunch/src/main/java/org/apache/crunch/types/avro/AvroType.java b/crunch/src/main/java/org/apache/crunch/types/avro/AvroType.java
index 6e35f5b..7aaec25 100644
--- a/crunch/src/main/java/org/apache/crunch/types/avro/AvroType.java
+++ b/crunch/src/main/java/org/apache/crunch/types/avro/AvroType.java
@@ -96,7 +96,23 @@ public class AvroType<T> implements PType<T> {
    * @return true if the wrapped type is a specific data type
    */
   public boolean isSpecific() {
-    return SpecificRecord.class.isAssignableFrom(typeClass);
+    if (Avros.isPrimitive(this)) {
+      return false;
+    }
+
+    boolean hasSpecific = false;
+    if (!this.subTypes.isEmpty()) {
+      for (PType<?> subType : this.subTypes) {
+        AvroType<?> atype = (AvroType<?>) subType;
+        if (atype.isReflect()) {
+          return false;
+        } else if (atype.isSpecific()) {
+          hasSpecific = true;
+        }
+      }
+    }
+    
+    return hasSpecific || SpecificRecord.class.isAssignableFrom(typeClass);
   }
 
   /**
@@ -119,7 +135,6 @@ public class AvroType<T> implements PType<T> {
     }
 
     if (!this.subTypes.isEmpty()) {
-
       for (PType<?> subType : this.subTypes) {
         if (((AvroType<?>) subType).isReflect()) {
           return true;

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/main/java/org/apache/crunch/types/avro/Avros.java
----------------------------------------------------------------------
diff --git a/crunch/src/main/java/org/apache/crunch/types/avro/Avros.java b/crunch/src/main/java/org/apache/crunch/types/avro/Avros.java
index 038f805..9f4a21d 100644
--- a/crunch/src/main/java/org/apache/crunch/types/avro/Avros.java
+++ b/crunch/src/main/java/org/apache/crunch/types/avro/Avros.java
@@ -33,6 +33,7 @@ import org.apache.avro.Schema.Type;
 import org.apache.avro.generic.GenericData;
 import org.apache.avro.generic.GenericRecord;
 import org.apache.avro.reflect.ReflectData;
+import org.apache.avro.specific.SpecificRecord;
 import org.apache.avro.util.Utf8;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -192,9 +193,18 @@ public class Avros {
   }
 
   public static final <T> AvroType<T> containers(Class<T> clazz) {
+    if (SpecificRecord.class.isAssignableFrom(clazz)) {
+      return (AvroType<T>) specifics((Class<SpecificRecord>) clazz);
+    }
     return reflects(clazz);
   }
 
+  public static final <T extends SpecificRecord> AvroType<T> specifics(Class<T>
clazz) {
+    T t = ReflectionUtils.newInstance(clazz, null);
+    Schema schema = t.getSchema();
+    return new AvroType<T>(clazz, schema, new AvroDeepCopier.AvroSpecificDeepCopier<T>(clazz,
schema));
+  }
+  
   public static final <T> AvroType<T> reflects(Class<T> clazz) {
     Schema schema = REFLECT_DATA_FACTORY.getReflectData().getSchema(clazz);
     return new AvroType<T>(clazz, schema, new AvroDeepCopier.AvroReflectDeepCopier<T>(clazz,
schema));

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/io/avro/AvroFileReaderFactoryTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/io/avro/AvroFileReaderFactoryTest.java
b/crunch/src/test/java/org/apache/crunch/io/avro/AvroFileReaderFactoryTest.java
index 28ff5ba..4c6adaa 100644
--- a/crunch/src/test/java/org/apache/crunch/io/avro/AvroFileReaderFactoryTest.java
+++ b/crunch/src/test/java/org/apache/crunch/io/avro/AvroFileReaderFactoryTest.java
@@ -107,12 +107,12 @@ public class AvroFileReaderFactoryTest {
         this.avroFile.getAbsolutePath()));
 
     Person expectedPerson = new Person();
-    expectedPerson.setAge(42);
-    expectedPerson.setName("John Doe");
+    expectedPerson.age = 42;
+    expectedPerson.name = "John Doe";
     List<CharSequence> siblingNames = Lists.newArrayList();
     siblingNames.add("Jimmy");
     siblingNames.add("Jane");
-    expectedPerson.setSiblingnames(siblingNames);
+    expectedPerson.siblingnames = siblingNames;
 
     Person person = recordIterator.next();
 

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java b/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
index bac93f4..d3e7dfa 100644
--- a/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/CollectionDeepCopierTest.java
@@ -32,9 +32,9 @@ public class CollectionDeepCopierTest {
   @Test
   public void testDeepCopy() {
     Person person = new Person();
-    person.setAge(42);
-    person.setName("John Smith");
-    person.setSiblingnames(Lists.<CharSequence> newArrayList());
+    person.age = 42;
+    person.name = "John Smith";
+    person.siblingnames = Lists.<CharSequence> newArrayList();
 
     Collection<Person> personCollection = Lists.newArrayList(person);
     CollectionDeepCopier<Person> collectionDeepCopier = new CollectionDeepCopier<Person>(Avros.records(Person.class));

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/types/TupleDeepCopierTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/TupleDeepCopierTest.java b/crunch/src/test/java/org/apache/crunch/types/TupleDeepCopierTest.java
index 017a813..c332285 100644
--- a/crunch/src/test/java/org/apache/crunch/types/TupleDeepCopierTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/TupleDeepCopierTest.java
@@ -32,9 +32,9 @@ public class TupleDeepCopierTest {
   @Test
   public void testDeepCopy_Pair() {
     Person person = new Person();
-    person.setName("John Doe");
-    person.setAge(42);
-    person.setSiblingnames(Lists.<CharSequence> newArrayList());
+    person.name = "John Doe";
+    person.age = 42;
+    person.siblingnames = Lists.<CharSequence> newArrayList();
 
     Pair<Integer, Person> inputPair = Pair.of(1, person);
     DeepCopier<Pair> deepCopier = new TupleDeepCopier<Pair>(

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
index 6e2d89e..af6acb8 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvroDeepCopierTest.java
@@ -20,7 +20,8 @@ package org.apache.crunch.types.avro;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotSame;
 
-import org.apache.avro.Schema;
+import java.util.List;
+
 import org.apache.avro.generic.GenericData.Record;
 import org.apache.crunch.test.Person;
 import org.apache.crunch.types.avro.AvroDeepCopier.AvroSpecificDeepCopier;
@@ -33,9 +34,9 @@ public class AvroDeepCopierTest {
   @Test
   public void testDeepCopySpecific() {
     Person person = new Person();
-    person.setName("John Doe");
-    person.setAge(42);
-    person.setSiblingnames(Lists.<CharSequence> newArrayList());
+    person.name = "John Doe";
+    person.age = 42;
+    person.siblingnames = Lists.<CharSequence> newArrayList();
 
     Person deepCopyPerson = new AvroSpecificDeepCopier<Person>(Person.class, Person.SCHEMA$)
         .deepCopy(person);
@@ -58,15 +59,30 @@ public class AvroDeepCopierTest {
     assertNotSame(record, deepCopyRecord);
   }
 
+  static class ReflectedPerson {
+    String name;
+    int age;
+    List<String> siblingnames;
+    
+    @Override
+    public boolean equals(Object other) {
+      if (other == null || !(other instanceof ReflectedPerson)) {
+        return false;
+      }
+      ReflectedPerson that = (ReflectedPerson) other;
+      return name.equals(that.name)&& age == that.age && siblingnames.equals(that.siblingnames);

+    }
+  }
+  
   @Test
   public void testDeepCopyReflect() {
-    Person person = new Person();
-    person.setName("John Doe");
-    person.setAge(42);
-    person.setSiblingnames(Lists.<CharSequence> newArrayList());
+    ReflectedPerson person = new ReflectedPerson();
+    person.name = "John Doe";
+    person.age = 42;
+    person.siblingnames = Lists.newArrayList();
 
-    Person deepCopyPerson = new AvroDeepCopier.AvroReflectDeepCopier<Person>(Person.class,
-        Person.SCHEMA$).deepCopy(person);
+    ReflectedPerson deepCopyPerson = new AvroDeepCopier.AvroReflectDeepCopier<ReflectedPerson>(
+        ReflectedPerson.class, Avros.reflects(ReflectedPerson.class).getSchema()).deepCopy(person);
 
     assertEquals(person, deepCopyPerson);
     assertNotSame(person, deepCopyPerson);

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
b/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
index ebd59a5..e5518f7 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvroGroupedTableTypeTest.java
@@ -36,14 +36,14 @@ public class AvroGroupedTableTypeTest {
   public void testGetDetachedValue() {
     Integer integerValue = 42;
     Person person = new Person();
-    person.setName("John Doe");
-    person.setAge(42);
-    person.setSiblingnames(Lists.<CharSequence> newArrayList());
+    person.name = "John Doe";
+    person.age = 42;
+    person.siblingnames = Lists.<CharSequence> newArrayList();
 
     Iterable<Person> inputPersonIterable = Lists.newArrayList(person);
     Pair<Integer, Iterable<Person>> pair = Pair.of(integerValue, inputPersonIterable);
 
-    PGroupedTableType<Integer, Person> groupedTableType = Avros.tableOf(Avros.ints(),
Avros.reflects(Person.class))
+    PGroupedTableType<Integer, Person> groupedTableType = Avros.tableOf(Avros.ints(),
Avros.specifics(Person.class))
         .getGroupedTableType();
 
     Pair<Integer, Iterable<Person>> detachedPair = groupedTableType.getDetachedValue(pair);

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
index 84f6a6d..37ed801 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvroTableTypeTest.java
@@ -36,13 +36,13 @@ public class AvroTableTypeTest {
   public void testGetDetachedValue() {
     Integer integerValue = 42;
     Person person = new Person();
-    person.setName("John Doe");
-    person.setAge(42);
-    person.setSiblingnames(Lists.<CharSequence> newArrayList());
+    person.name = "John Doe";
+    person.age = 42;
+    person.siblingnames = Lists.<CharSequence> newArrayList();
 
     Pair<Integer, Person> pair = Pair.of(integerValue, person);
 
-    AvroTableType<Integer, Person> tableType = Avros.tableOf(Avros.ints(), Avros.reflects(Person.class));
+    AvroTableType<Integer, Person> tableType = Avros.tableOf(Avros.ints(), Avros.specifics(Person.class));
 
     Pair<Integer, Person> detachedPair = tableType.getDetachedValue(pair);
 

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/types/avro/AvroTypeTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvroTypeTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvroTypeTest.java
index 28777f5..955467c 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvroTypeTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvroTypeTest.java
@@ -72,7 +72,7 @@ public class AvroTypeTest {
 
   @Test
   public void testIsSpecific_SpecificAvroTable() {
-    assertFalse(Avros.tableOf(Avros.strings(), Avros.records(Person.class)).isSpecific());
+    assertTrue(Avros.tableOf(Avros.strings(), Avros.records(Person.class)).isSpecific());
   }
 
   @Test
@@ -162,28 +162,46 @@ public class AvroTypeTest {
   
   private Person createPerson(){
     Person person = new Person();
-    person.setName("name value");
-    person.setAge(42);
-    person.setSiblingnames(Lists.<CharSequence> newArrayList());
+    person.name = "name value";
+    person.age = 42;
+    person.siblingnames = Lists.<CharSequence> newArrayList();
     return person;
   }
 
   @Test
   public void testGetDetachedValue_SpecificAvroType() {
-    AvroType<Person> specificType = Avros.records(Person.class);
+    AvroType<Person> specificType = Avros.specifics(Person.class);
     Person person = createPerson();
     Person detachedPerson = specificType.getDetachedValue(person);
     assertEquals(person, detachedPerson);
     assertNotSame(person, detachedPerson);
   }
 
+  static class ReflectedPerson {
+    String name;
+    int age;
+    List<String> siblingnames;
+    
+    @Override
+    public boolean equals(Object other) {
+      if (other == null || !(other instanceof ReflectedPerson)) {
+        return false;
+      }
+      ReflectedPerson that = (ReflectedPerson) other;
+      return name.equals(that.name)&& age == that.age && siblingnames.equals(that.siblingnames);

+    }
+  }
+  
   @Test
   public void testGetDetachedValue_ReflectAvroType() {
-    AvroType<Person> reflectType = Avros.reflects(Person.class);
-    Person person = createPerson();
-    Person detachedPerson = reflectType.getDetachedValue(person);
-    assertEquals(person, detachedPerson);
-    assertNotSame(person, detachedPerson);
+    AvroType<ReflectedPerson> reflectType = Avros.reflects(ReflectedPerson.class);
+    ReflectedPerson rp = new ReflectedPerson();
+    rp.name = "josh";
+    rp.age = 32;
+    rp.siblingnames = Lists.newArrayList();
+    ReflectedPerson detached = reflectType.getDetachedValue(rp);
+    assertEquals(rp, detached);
+    assertNotSame(rp, detached);
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/b8891e54/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
----------------------------------------------------------------------
diff --git a/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java b/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
index 6e66f74..801829d 100644
--- a/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
+++ b/crunch/src/test/java/org/apache/crunch/types/avro/AvrosTest.java
@@ -274,13 +274,13 @@ public class AvrosTest {
     Person personA = new Person();
     Person personB = new Person();
 
-    personA.setAge(1);
-    personA.setName("A");
-    personA.setSiblingnames(Collections.<CharSequence> emptyList());
+    personA.age = 1;
+    personA.name = "A";
+    personA.siblingnames = Collections.<CharSequence> emptyList();
 
-    personB.setAge(2);
-    personB.setName("B");
-    personB.setSiblingnames(Collections.<CharSequence> emptyList());
+    personB.age = 2;
+    personB.name = "B";
+    personB.siblingnames = Collections.<CharSequence> emptyList();
 
     AvroType<Pair<Person, Person>> pairType = Avros.pairs(Avros.records(Person.class),
Avros.records(Person.class));
 


Mime
View raw message