A green,190 A blue,300 A yellow,299 A blue,199 ... As all the key values are same, hence it will go to single reducer, in single reduce() method call. In the reducer method we will have One TreeMap java collection, which stored sorted map based on the key. And ArrayList will store all the width of a particular color. So the TreeMap will be storing the values as below. blue (199,300) green (190,199,799) yellow (299,299)
Now it will iterate over the TreeMap and reverse sort the values stored in the ArrayList. After reverse sorting it emits the output as below. blue,300 blue,199 green,799 green,199 ... As desired output
Explanation: Mapper emits the following key and value pair
A green,190 A blue,300 A yellow,299 A blue,199 A green,199 A yellow,299 A green,799
In the TreeMap, it stores all the key as color and value part contains all the widths in an ArrayList objects. As TreeMap already stores the sorted color as key in reverse order as it is instantiated like that only. And we sort the each instance of the ArrayList in ascending order by iteration on the TreeMap and emit the each color and width combination which produces the output as belwo.