A complete mapper
Sunday, February 28, 2010
1:11 PM
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class WordCountMapper extends MapReduceBase
implements Mapper<LongWritable, Text, Text, IntWritable> {
 private final IntWritable one = new IntWritable(1);
 private Text word = new Text();
 // do a map operation: count words in a given string
 public void map(WritableComparable key, Writable value,
  OutputCollector<Text, IntWritable> output, Reporter reporter) 
throws IOException {
  String line = value.toString();
  StringTokenizer itr = new StringTokenizer(line.toLowerCase());
  while(itr.hasMoreTokens()) {
   word.set(itr.nextToken());
   output.collect(word, one); // add one!
  }
 }
}
Pasted from <[link]> 