You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@crunch.apache.org by jw...@apache.org on 2014/06/12 05:41:42 UTC

git commit: CRUNCH-419 Writables.registerComparable does not actually register the WritableComparable

Repository: crunch
Updated Branches:
  refs/heads/master 772f7f2b2 -> 96ef2d679


CRUNCH-419 Writables.registerComparable does not actually register the WritableComparable

Signed-off-by: Josh Wills <jw...@apache.org>


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

Branch: refs/heads/master
Commit: 96ef2d679c9a7bf6c2cb80190e0646f94f558482
Parents: 772f7f2
Author: Tom De Leu <de...@gmail.com>
Authored: Wed Jun 11 22:09:08 2014 +0200
Committer: Josh Wills <jw...@apache.org>
Committed: Wed Jun 11 20:04:10 2014 -0700

----------------------------------------------------------------------
 .../apache/crunch/types/writable/Writables.java    |  1 +
 .../crunch/types/writable/WritablesTest.java       | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/crunch/blob/96ef2d67/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java
----------------------------------------------------------------------
diff --git a/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java b/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java
index f571f2f..be2cb1a 100644
--- a/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java
+++ b/crunch-core/src/main/java/org/apache/crunch/types/writable/Writables.java
@@ -122,6 +122,7 @@ public class Writables {
     if (WRITABLE_CODES.containsKey(code)) {
       throw new IllegalArgumentException("Already have writable class assigned to code = " + code);
     }
+    WRITABLE_CODES.put(code, clazz);
   }
 
   private static final String WRITABLE_COMPARABLE_CODES = "crunch.writable.comparable.codes";

http://git-wip-us.apache.org/repos/asf/crunch/blob/96ef2d67/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
----------------------------------------------------------------------
diff --git a/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java b/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
index 70099f2..2281473 100644
--- a/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
+++ b/crunch-core/src/test/java/org/apache/crunch/types/writable/WritablesTest.java
@@ -42,7 +42,7 @@ import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.NullWritable;
 import org.apache.hadoop.io.Text;
-import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.io.WritableUtils;
 import org.junit.Test;
 
@@ -172,7 +172,7 @@ public class WritablesTest {
     testInputOutputFn(wt, j, w);
   }
 
-  protected static class TestWritable implements Writable {
+  protected static class TestWritable implements WritableComparable<TestWritable> {
     String left;
     int right;
 
@@ -207,6 +207,13 @@ public class WritablesTest {
       return true;
     }
 
+    @Override
+    public int compareTo(TestWritable o) {
+      int cmp = left.compareTo(o.left);
+      if (cmp != 0)
+        return cmp;
+      return Integer.valueOf(right).compareTo(Integer.valueOf(o.right));
+    }
   }
 
   @Test
@@ -236,6 +243,12 @@ public class WritablesTest {
     assertSame(Writables.records(TestWritable.class), wt);
   }
 
+  @Test
+  public void testRegisterComparable() throws Exception {
+    Writables.registerComparable(TestWritable.class);
+    assertNotNull(Writables.WRITABLE_CODES.inverse().get(TestWritable.class));
+  }
+
   @SuppressWarnings({ "unchecked", "rawtypes" })
   protected static void testInputOutputFn(PType ptype, Object java, Object writable) {
     ptype.getInputMapFn().initialize();