hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r691306 - in /hadoop/core/trunk: CHANGES.txt src/core/org/apache/hadoop/io/WritableComparator.java src/test/org/apache/hadoop/mapred/TestComparators.java
Date Tue, 02 Sep 2008 16:27:39 GMT
Author: omalley
Date: Tue Sep  2 09:27:38 2008
New Revision: 691306

URL: http://svn.apache.org/viewvc?rev=691306&view=rev
Log:
HADOOP-4046. Made WritableComparable's constructor protected instead of 
private to re-enable class derivation. (cdouglas via omalley)

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/core/org/apache/hadoop/io/WritableComparator.java
    hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestComparators.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=691306&r1=691305&r2=691306&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Tue Sep  2 09:27:38 2008
@@ -457,6 +457,9 @@
     from the TaskTracker, which was causing HDFS client connections to not be 
     collected. (ddas via omalley)
 
+    HADOOP-4046. Made WritableComparable's constructor protected instead of 
+    private to re-enable class derivation. (cdouglas via omalley)
+
 Release 0.18.0 - 2008-08-19
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/core/org/apache/hadoop/io/WritableComparator.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/io/WritableComparator.java?rev=691306&r1=691305&r2=691306&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/io/WritableComparator.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/io/WritableComparator.java Tue Sep  2 09:27:38
2008
@@ -63,7 +63,7 @@
     this(keyClass, false);
   }
 
-  private WritableComparator(Class<? extends WritableComparable> keyClass,
+  protected WritableComparator(Class<? extends WritableComparable> keyClass,
       boolean createInstances) {
     this.keyClass = keyClass;
     if (createInstances) {

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestComparators.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestComparators.java?rev=691306&r1=691305&r2=691306&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestComparators.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestComparators.java Tue Sep  2 09:27:38
2008
@@ -420,5 +420,48 @@
       fail("Oops! The job broke due to an unexpected error");
     }
   }
-  
+
+  /**
+   * Test a user comparator that relies on deserializing both arguments
+   * for each compare.
+   */
+  public void testBakedUserComparator() throws Exception {
+    MyWritable a = new MyWritable(8, 8);
+    MyWritable b = new MyWritable(7, 9);
+    assertTrue(a.compareTo(b) > 0);
+    assertTrue(WritableComparator.get(MyWritable.class).compare(a, b) < 0);
+  }
+
+  public static class MyWritable implements WritableComparable<MyWritable> {
+    int i, j;
+    public MyWritable() { }
+    public MyWritable(int i, int j) {
+      this.i = i;
+      this.j = j;
+    }
+    public void readFields(DataInput in) throws IOException {
+      i = in.readInt();
+      j = in.readInt();
+    }
+    public void write(DataOutput out) throws IOException {
+      out.writeInt(i);
+      out.writeInt(j);
+    }
+    public int compareTo(MyWritable b) {
+      return this.i - b.i;
+    }
+    static {
+      WritableComparator.define(MyWritable.class, new MyCmp());
+    }
+  }
+
+  public static class MyCmp extends WritableComparator {
+    public MyCmp() { super(MyWritable.class, true); }
+    public int compare(WritableComparable a, WritableComparable b) {
+      MyWritable aa = (MyWritable)a;
+      MyWritable bb = (MyWritable)b;
+      return aa.j - bb.j;
+    }
+  }
+
 }



Mime
View raw message