Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse Sorting Reducer Keys

What is the best approach to get the Map Output keys to a reducer in reverse order? By default the reducer receives all keys in ascending order of keys. Any help or comments widely appreciated.

In simple words, in the normal scenario, if a map emits keys 1,4,3,5,2 the reducer receives the same as 1,2,3,4,5. I would like the reducer to receive 5,4,3,2,1 instead.

like image 233
Arun A K Avatar asked Dec 26 '22 20:12

Arun A K


1 Answers

In Hadoop 1.X, you can specify a custom comparator class for your outputs using JobConf.setOutputKeyComparatorClass.

Your comparator must implement the RawComparator interface.

With Hadoop 2.X, this is done by using Job.setSortComparatorClass, still with an implementation of RawComparator.

like image 81
Wookai Avatar answered Jan 03 '23 06:01

Wookai