I have a file containing a String, then a space and then a number on every line.
Example:
Line1: Word 2
Line2 : Word1 8
Line3: Word2 1
I need to sort the number in descending order and then put the result in a file assigning a rank to the numbers. So my output should be a file containing the following format:
Line1: Word1 8 1
Line2: Word 2 2
Line3: Word2 1 3
Does anyone has an idea, how can I do it in Hadoop?
I am using java with Hadoop.
I devised the solution to this problem. It was simple actually.
For sorting by value you need to use
For sorting in decreasing order you need to use
setSortComparatorClass(LongWritable.DecreasingComparator.class);For ranking you need to use
Counter class,getCounterandincrementfunction.