Dear All,
Here i bring you new sizecount program of MapReduce. Hope this will help for all of you.
public class SizeCount
{
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable>
{
public void map(LongWritable key, Text value,OutputCollector<Text, IntWritable> output, Reporter report) throws IOException
{
String sentence=value.toString();
StringTokenizer token=new StringTokenizer(sentence);
while(token.hasMoreTokens())
{
value.set(String.valueOf(token.nextToken().length()));
output.collect(value, new IntWritable(1));
}
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterator<IntWritable> values,OutputCollector<Text, IntWritable> output, Reporter report)throws IOException
{
int sum=0;
while(values.hasNext())
{
sum+=values.next().get();
}
output.collect(key, new IntWritable(sum));
}
}
No comments:
Post a Comment