Sie sind auf Seite 1von 1

public class MapperClass1 extends MapReduceBase

implements Mapper<LongWritable , Text, Text, IntWritable>{



@Override
public void map(LongWritable key1, Text value, OutputCollector<Text,
IntWritable> output,
Reporter reporter) throws IOException {

String row = value.toString();
for (String word : row.split(",")){
if(word.length()>0){
output.collect(new Text(word), new IntWritable(1));
}
}

}




public class ReducerClass1 extends MapReduceBase implements
Reducer<Text, IntWritable, Text, IntWritable> {
//Input Key, Input Value , Output Key, Output Value
@Override
public void reduce(Text key, Iterator<IntWritable> values,
//Input Key, Iterator<Input Value>
OutputCollector<Text, IntWritable> output, Reporter reporter)
//output <Output Key, Output Value>
throws IOException {
int wordcount=0;
while(values.hasNext()){
wordcount += values.next().get();
}
output.collect(key, new IntWritable(wordcount));
}

Das könnte Ihnen auch gefallen