Created
October 5, 2012 13:08
-
-
Save geofferyzh/3839714 to your computer and use it in GitHub Desktop.
Hadoop 101 - Descending Sort
This file contains 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
// 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.FloatWritable; | |
import org.apache.hadoop.io.WritableComparable; | |
import org.apache.hadoop.io.WritableComparator; | |
public class SortFloatComparator extends WritableComparator { | |
//Constructor. | |
protected SortFloatComparator() { | |
super(FloatWritable.class, true); | |
} | |
@SuppressWarnings("rawtypes") | |
@Override | |
public int compare(WritableComparable w1, WritableComparable w2) { | |
FloatWritable k1 = (FloatWritable)w1; | |
FloatWritable k2 = (FloatWritable)w2; | |
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
Hi,
I would like to thank you for posting this here, that is very helpful.
I am actually trying to let it run on my word count program, but I am stuck there.
Could u please post the whole code.
Thank You