hadoop-common-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Savannah Beckett <savannah_becket...@yahoo.com>
Subject How to do Secondary Sort on a String and a float?
Date Sun, 26 Dec 2010 05:05:52 GMT
I am writing a Secondary Sort to sort a String key and float value.  I am 
following the example in 
mapred/src/examples/org/apache/hadoop/examples/SecondarySort.java in the hadoop 
package.  The example is for a pair of integers.  I did lots of research online 
but most of them were still using the old API.  It seems that for the new API, I 
have to implement the RawComparator interface which means I need to write the 
compare byte function no matter what.  


I have problem with this code:
  public static class FirstGroupingComparator
                implements RawComparator<IntPair> {
    @Override
    public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
      return WritableComparator.compareBytes(b1, s1, Integer.SIZE/8,
                                             b2,
s2, Integer.SIZE/8);
    }
    @Override
    public int compare(IntPair o1, IntPair o2) {
      int l = o1.getFirst();
      int r = o2.getFirst();
      return l == r ? 0 : (l < r ? -1 : 1);
    }
  }


How do I write the code inside the first compare function?  What should I put as 
the length of the String and float (primitive type) in the compareBytes 
function?  Does anyone have any examples for a pair of String and float?

Thanks.  Merry Christmas.



      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message