Database Reference
In-Depth Information
21 public void map(LongWritable key, Text value, OutputCollector<Text,
22 IntWritable output, Reporter reporter) throws IOException
23 {
24 String line = value.toString();
25 StringTokenizer tokenizer = new StringTokenizer(line);
26 while (tokenizer.hasMoreTokens())
27 {
28 word.set(tokenizer.nextToken());
29 output.collect(word, one);
30 }
31 }
32 } /* class Map */
33
34 public static class Reduce extends MapReduceBase implements
35 Reducer<Text, IntWritable, Text, IntWritable>
36 {
37 public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException
39 {
40 int sum = 0;
41 while (values.hasNext())
42 {
43 sum += values.next().get();
44 }
45 output.collect(key, new IntWritable(sum));
46 }
47 } /* class Reduce */
48
49 public static void main(String[] args) throws Exception
50 {
51 JobConf conf = new JobConf(WordCount.class);
52 conf.setJobName("wordcount");
53
54 conf.setOutputKeyClass(Text.class);
55 conf.setOutputValueClass(IntWritable.class);
56
57 conf.setMapperClass(Map.class);
58 conf.setCombinerClass(Reduce.class);
59 conf.setReducerClass(Reduce.class);
60
61 conf.setInputFormat(TextInputFormat.class);
62 conf.setOutputFormat(TextOutputFormat.class);
63
64 FileInputFormat.setInputPaths(conf, new Path(args[0]));
65 FileOutputFormat.setOutputPath(conf, new Path(args[1]));
66
67 JobClient.runJob(conf);
68 }
69
70 } /* class WordCount */
Search WWH ::




Custom Search