I'm thinking about building a small testing application in hadoop to get the hang of the system.

The application I have in mind will be in the realm of doing statistics.
I want to have "The 10 worst values for each key" from my reducer function (where I must assume the possibility a huge number of values for some keys).

What I have planned is that the values that go into my reducer will basically be the combination of "The actual value" and "The quality/relevance of the actual value".
Based on the relevance I "simply" want to take the 10 worst/best values and output them from the reducer.

How do I go about doing that (assuming a huge number of values for a specific key)? 
Is there a way that I can sort all values BEFORE they are sent into the reducer (and simply stop reading the input when I have read the first 10) or must this be done differently? 

Can someone here point me to a piece of example code I can have a look at?

---

Update: I found two interesting Jira issues [HADOOP-485](http://issues.apache.org/jira/browse/HADOOP-485) and [HADOOP-686](http://issues.apache.org/jira/browse/HADOOP-686).

Anyone has a code fragment on how to use this in the Hadoop 0.20 API?