You can fully shortcut your reducer by overriding the default implementation of the Reducer.run()
method:
public void run(Context context) throws IOException, InterruptedException {
setup(context);
while (context.nextKey()) {
reduce(context.getCurrentKey(), context.getValues(), context);
}
cleanup(context);
}
You should be able to amend the while loop to include your counter as follows:
public void run(Context context) throws IOException, InterruptedException {
setup(context);
int count = 0;
while (context.nextKey() && count++ < 1000) {
reduce(context.getCurrentKey(), context.getValues(), context);
}
cleanup(context);
}
Not that this won't necessarily output the top most records, merely the first 1000 keyed records (and will not work if your reduce implementation outputs more that a single record - in which case you can increment the counter in the reduce method)