Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static void registerComparable(Class<? extends WritableComparable> clazz,
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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;

Expand Down Expand Up @@ -172,7 +172,7 @@ public void testTupleN() throws Exception {
testInputOutputFn(wt, j, w);
}

protected static class TestWritable implements Writable {
protected static class TestWritable implements WritableComparable<TestWritable> {
String left;
int right;

Expand Down Expand Up @@ -207,6 +207,13 @@ public boolean equals(Object obj) {
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
Expand Down Expand Up @@ -236,6 +243,12 @@ public void testRegister() throws Exception {
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();
Expand Down