wiki:waue/2009/0715

Version 2 (modified by waue, 15 years ago) (diff)

--

public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {

while (tokenizer.hasMoreTokens()) {
		private final static IntWritable one = new IntWritable(1);
		private Text word = new Text();
		output.collect(word, one);

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 reporter)	throws IOException {
int sum = 0;
while (values.hasNext()) {
	sum += values.next().get();
}
output.collect(key, new IntWritable(sum));