Created
February 3, 2011 17:18
-
-
Save noiano/809803 to your computer and use it in GitHub Desktop.
GroupingComparator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GroupingComparator implements RawComparator<PairOfStringInt>{ | |
private static final Text.Comparator TEXT_COMPARATOR = new Text.Comparator(); | |
@Override | |
public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { | |
return TEXT_COMPARATOR.compare(b1, s1, l1, b2, s2, l2); | |
/* | |
int firstL1;; | |
int firstL2; | |
try{ | |
firstL1 = WritableUtils.decodeVIntSize(b1[s1]) + WritableComparator.readVInt(b1, s1); | |
firstL2 = WritableUtils.decodeVIntSize(b2[s2]) + WritableComparator.readVInt(b2, s2); | |
return TEXT_COMPARATOR.compare(b1, s1, firstL1, b2, s2, firstL2); | |
} | |
catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
*/ | |
} | |
@Override | |
public int compare(PairOfStringInt p1, PairOfStringInt p2) { | |
return p1.getLeftElement().compareTo(p2.getLeftElement()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your value grouping comparator seems right for the apples example you gave on the ML, but you need your Partitioner to support it by looking up on the same part of your composite key.