You can arrange the calculation of the map / abbreviation as follows:
Card input: default
Card Output: "key: number, value: word"
_ key sorting phase _
Here you need to override the default sorter to sort in descending order.
Reduction - 1 gear
Reduce input: "key: number, value: word"
Reduce output: "key: word, value: (number, rank)"
Keep a global counter. For each key-value pair, add a rank by increasing the counter.
Change Here is the code cut off from a custom descendant sorter:
public static class IntComparator extends WritableComparator { public IntComparator() { super(IntWritable.class); } @Override public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { Integer v1 = ByteBuffer.wrap(b1, s1, l1).getInt(); Integer v2 = ByteBuffer.wrap(b2, s2, l2).getInt(); return v1.compareTo(v2) * (-1); } }
Remember to set it as a comparator for your work:
job.setSortComparatorClass(IntComparator.class);
Tudor source share