hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r691308 - in /hadoop/core/branches/branch-0.18: CHANGES.txt src/core/org/apache/hadoop/io/WritableComparator.java src/test/org/apache/hadoop/mapred/TestComparators.java
Date Tue, 02 Sep 2008 16:31:31 GMT
Author: omalley
Date: Tue Sep  2 09:31:30 2008
New Revision: 691308

URL: http://svn.apache.org/viewvc?rev=691308&view=rev
Log:
HADOOP-4046. Merge -r 691305:691306 from trunk to branch 0.18

Modified:
    hadoop/core/branches/branch-0.18/CHANGES.txt
    hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/io/WritableComparator.java
    hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/mapred/TestComparators.java

Modified: hadoop/core/branches/branch-0.18/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/CHANGES.txt?rev=691308&r1=691307&r2=691308&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.18/CHANGES.txt Tue Sep  2 09:31:30 2008
@@ -14,6 +14,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/branches/branch-0.18/src/core/org/apache/hadoop/io/WritableComparator.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/io/WritableComparator.java?rev=691308&r1=691307&r2=691308&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/io/WritableComparator.java
(original)
+++ hadoop/core/branches/branch-0.18/src/core/org/apache/hadoop/io/WritableComparator.java
Tue Sep  2 09:31:30 2008
@@ -63,7 +63,7 @@
     this(keyClass, false);
   }
 
-  private WritableComparator(Class keyClass, boolean createInstances) {
+  protected WritableComparator(Class keyClass, boolean createInstances) {
     this.keyClass = keyClass;
     if (createInstances) {
       key1 = newKey();

Modified: hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/mapred/TestComparators.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/mapred/TestComparators.java?rev=691308&r1=691307&r2=691308&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/mapred/TestComparators.java
(original)
+++ hadoop/core/branches/branch-0.18/src/test/org/apache/hadoop/mapred/TestComparators.java
Tue Sep  2 09:31:30 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