hadoop-mapreduce-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bhasker Allene <allene.bhas...@gmail.com>
Subject Re: How can I sort a file with pairs <Key Value> in reverse order?
Date Tue, 11 Jun 2013 11:57:07 GMT
One way to approach is emit |Integer.MAX_VALUE - your key ||as output of 
mapper.|
Example
Mapper input
7 vim
2 emacs
9 firefox

Mapper output
(Integer.MAX_VALUE - 7) vim
(Integer.MAX_VALUE - 2) emacs
(Integer.MAX_VALUE - 9) firefox

If you need secondary sorting on second part, you have to use composite 
key  and write  your own petitioner, comparator.

Regards,
Bhasker

On 11/06/2013 11:10, Pedro Sá da Costa wrote:
> I created a MapReduce job example that that uses the sort mechanism of 
> hadoop to sort a file by the key in ascending order. This is an 
> example of the data:
>
> 7    vim
> 2    emacs
> 9    firefox
>
> At the end, I get the result:
>
> 2    emacs
> 7    vim
> 9    firefox
>
>
>
> Now I want to sort in reverse order, for the result be:
> 9    firefox
> 7    vim
> 2    emacs
>
>
>
> How can I sort a file with pairs <Key Value> in reverse order?
>
> -- 
> Best regards,


-- 
Thanks & Regards,
Bhasker Allene


Mime
View raw message