You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by dd...@apache.org on 2009/05/27 04:12:16 UTC

svn commit: r778962 - in /hadoop/core/trunk: CHANGES.txt src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedComparator.java src/test/mapred/org/apache/hadoop/mapred/lib/TestKeyFieldBasedComparator.java

Author: ddas
Date: Wed May 27 02:12:16 2009
New Revision: 778962

URL: http://svn.apache.org/viewvc?rev=778962&view=rev
Log:
HADOOP-5816. Fixes a problem in the KeyFieldBasedComparator to do with ArrayIndexOutOfBounds exception. Contributed by He Yongqiang .

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedComparator.java
    hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/lib/TestKeyFieldBasedComparator.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=778962&r1=778961&r2=778962&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed May 27 02:12:16 2009
@@ -767,6 +767,9 @@
     HADOOP-5850. Fixes a problem to do with not being able to jobs with
     0 maps/reduces. (Vinod K V via ddas)
 
+    HADOOP-5816. Fixes a problem in the KeyFieldBasedComparator to do with
+    ArrayIndexOutOfBounds exception. (He Yongqiang via ddas)
+
 Release 0.20.0 - 2009-04-15
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedComparator.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedComparator.java?rev=778962&r1=778961&r2=778962&view=diff
==============================================================================
--- hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedComparator.java (original)
+++ hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/lib/KeyFieldBasedComparator.java Wed May 27 02:12:16 2009
@@ -106,7 +106,7 @@
     }
     int compareResult = 0;
     if (!key.numeric) {
-      compareResult = compareBytes(first, start1, end1, second, start2, end2);
+      compareResult = compareBytes(first, start1, end1-start1+1, second, start2, end2-start2+1);
     }
     if (key.numeric) {
       compareResult = numericalCompare (first, start1, end1, second, start2, end2);

Modified: hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/lib/TestKeyFieldBasedComparator.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/lib/TestKeyFieldBasedComparator.java?rev=778962&r1=778961&r2=778962&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/lib/TestKeyFieldBasedComparator.java (original)
+++ hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/lib/TestKeyFieldBasedComparator.java Wed May 27 02:12:16 2009
@@ -38,12 +38,16 @@
 
 public class TestKeyFieldBasedComparator extends HadoopTestCase {
   JobConf conf;
-  String line1 = "123 -123 005120 123.9 0.01 0.18 010 10.1 4444 011 011 234";
-  String line2 = "134 -12 005100 123.10 -1.01 0.19 02 10.0 4444.1";
+  JobConf localConf;
+  
+  String line1 = "123 -123 005120 123.9 0.01 0.18 010 10.0 4444.1 011 011 234";
+  String line2 = "134 -12 005100 123.10 -1.01 0.19 02 10.1 4444";
 
   public TestKeyFieldBasedComparator() throws IOException {
     super(HadoopTestCase.LOCAL_MR, HadoopTestCase.LOCAL_FS, 1, 1);
     conf = createJobConf();
+    localConf = createJobConf();
+    localConf.set("map.output.key.field.separator", " ");
   }
   public void configure(String keySpec, int expect) throws Exception {
     Path testdir = new Path("build/test/test.mapred.spill");
@@ -123,9 +127,24 @@
     configure("-k2.4,2.4n", 2);
     configure("-k7,7", 1);
     configure("-k7,7n", 2);
-    configure("-k8,8n", 2);
-    configure("-k9,9n", 1);
+    configure("-k8,8n", 1);
+    configure("-k9,9", 2);
     configure("-k11,11",2);
     configure("-k10,10",2);
+    
+    localTestWithoutMRJob("-k9,9", 1);
+  }
+  
+  byte[] line1_bytes = line1.getBytes();
+  byte[] line2_bytes = line2.getBytes();
+
+  public void localTestWithoutMRJob(String keySpec, int expect) throws Exception {
+    KeyFieldBasedComparator<Void, Void> keyFieldCmp = new KeyFieldBasedComparator<Void, Void>();
+    localConf.setKeyFieldComparatorOptions(keySpec);
+    keyFieldCmp.configure(localConf);
+    int result = keyFieldCmp.compare(line1_bytes, 0, line1_bytes.length,
+        line2_bytes, 0, line2_bytes.length);
+    if ((expect >= 0 && result < 0) || (expect < 0 && result >= 0))
+      fail();
   }
 }