Changes between Version 9 and Version 10 of waue/2009/0715


Ignore:
Timestamp:
Jul 15, 2009, 5:36:30 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0715

    v9 v10  
    1818{{{
    1919#!java
    20 14.          public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
    21 15.          private final static IntWritable one = new IntWritable(1);
    22 16.          private Text word = new Text();
    23 17.     
    24 18.          public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
    25 19.            String line = value.toString();
    26 20.            StringTokenizer tokenizer = new StringTokenizer(line);
    27 21.            while (tokenizer.hasMoreTokens()) {
    28 22.              word.set(tokenizer.nextToken());
    29 23.              output.collect(word, one);
    30 24.            }
    31 25.          }
    32 26.        }
    33 27.     
    34 28.        public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
    35 29.          public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
    36 30.            int sum = 0;
    37 31.            while (values.hasNext()) {
    38 32.              sum += values.next().get();
    39 33.            }
    40 34.            output.collect(key, new IntWritable(sum));
    41 35.          }
    42 36.        }
     20public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
     21private final static IntWritable one = new IntWritable(1);
     22private Text word = new Text();
     23
     24public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
     25  String line = value.toString();
     26  StringTokenizer tokenizer = new StringTokenizer(line);
     27  while (tokenizer.hasMoreTokens()) {
     28    word.set(tokenizer.nextToken());
     29    output.collect(word, one);
     30  }
     31}
     32
     33public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
     34  public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
     35    int sum = 0;
     36    while (values.hasNext()) {
     37      sum += values.next().get();
     38    }
     39    output.collect(key, new IntWritable(sum));
     40  }
     41}
    4342}}}