/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.examples;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

//test git
public class WordCount {

  public static class TokenizerMapper
       extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value, Context context
                    ) throws IOException, InterruptedException {
      StringTokenizer itr = new StringTokenizer(value.toString());
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer
       extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values,
                       Context context
                       ) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

  public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length < 2) {
      System.err.println("Usage: wordcount <in> [<in>...] <out>");
      System.exit(2);
    }
    Job job = Job.getInstance(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    for (int i = 0; i < otherArgs.length - 1; ++i) {
      FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
    }
    FileOutputFormat.setOutputPath(job,
      new Path(otherArgs[otherArgs.length - 1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}

@@ -900,16 +900,90 @@
 nizer;%0A%0A
+// You will typically import these classes every mapreduce job you write.%0A
 import o
@@ -1440,16 +1440,107 @@
 %0A%0A//
-test git
+ MapReduce program genrally consist of three portions: The Mapper, the reducer and the driver codee
 %0Apub
@@ -1753,24 +1753,293 @@
 ew Text();%0A%0A
+    // The Mapper implementation, via the map method, processes one line at a time, as provided by the%0A%09// specified TextInputFormat. It then splits the line into tokens separated by whitespaces,%0A%09// via the StringTokenizer, and emits a key-value pair of %3C %3Cword%3E, 1%3E.%0A
     public v
@@ -2486,24 +2486,186 @@
 Writable();%0A
+    // The Reducer implementation, via the reduce method just sums up the values,%0A    // which are the occurence counts for each key (i.e. words in this example).
 %0A    public 
@@ -2989,65 +2989,330 @@
 %0A%0A  
-public static void main(String%5B%5D args) throws Exception %7B
+// Usually configure your mapreduce job in the main method.%0A  public static void main(String%5B%5D args) throws Exception %7B%0A        // To configure your mapreduce job, create a new Configuration object. some use the Hadoop default values%0A    // some options will read from the Hadoop configuration files, e.g. /etc/hadoop/conf
 %0A   
@@ -3350,24 +3350,25 @@
 guration();%0A
+%0A
     String%5B%5D
@@ -3559,24 +3559,74 @@
 it(2);%0A    %7D
+%0A%0A    // Give the mapreduce job a meaningful name.
 %0A    Job job
@@ -3673,43 +3673,200 @@
     
-job.setJarByClass(WordCount.class);
+//specicify the class which will be called to run the mapreduce job.%0A    job.setJarByClass(WordCount.class);%0A    // Give the job about which class are be instatiated as the mapper and reducer.
 %0A   
@@ -4085,24 +4085,496 @@
 ble.class);%0A
+    // specify the input directory from which data will be read.%0A    // The data passed to the mapper is specified by an inputformat, in this case, it is FileInputFormat%0A%09// The InputFormat determines how to split the input data into input splites. Each mapper will deal%0A%09// with a single input split.InputFormat is a factory for RecordReader objects to extract (key,value)%0A    // records from the input source. output directory to which the final output will be written.%0A
     for (int
@@ -4771,24 +4771,44 @@
 gth - 1%5D));%0A
+    // run the job.%0A
     System.e

Add comments