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> {
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);
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.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupcommon-user @
postedDec 26, '10 at 5:06a
activeDec 26, '10 at 8:38a

2 users in discussion

Harsh J: 1 post Savannah Beckett: 1 post



site design / logo © 2022 Grokbase