Skip to content

Instantly share code, notes, and snippets.

@leepro
Forked from geofferyzh/descendingsort.java
Last active December 22, 2015 02:19
Show Gist options
  • Save leepro/6402440 to your computer and use it in GitHub Desktop.
Save leepro/6402440 to your computer and use it in GitHub Desktop.
// Set Sort Comparator Class in the Driver code
job.setSortComparatorClass(SortFloatComparator.class);
// Write a Sort Comparator and save as "SortFloatComparator.java"
import java.io.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;
public class SortFloatComparator extends WritableComparator {
//Constructor.
protected SortFloatComparator() {
super(Text.class, true);
}
@SuppressWarnings("rawtypes")
@Override
public int compare(WritableComparable w1, WritableComparable w2) {
String k1 = ((Text)w1).toString();
String k2 = ((Text)w2).toString();
return -1 * k1.compareTo(k2);
}
}
// Mapper and Reducer Codes here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment