Skip to content

Instantly share code, notes, and snippets.

@dapurv5
Created January 15, 2012 02:17
Show Gist options
  • Save dapurv5/1613930 to your computer and use it in GitHub Desktop.
Save dapurv5/1613930 to your computer and use it in GitHub Desktop.
package wordcount;
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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class MyWordcount {
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: mrcount <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "mrcount");
job.setJobName("MyWordcount");
job.setJarByClass(MyWordcount.class);
job.setMapperClass(MyTokenCounterMapper.class);
job.setCombinerClass(MyTokenCounterReducer.class);
job.setReducerClass(MyTokenCounterReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.submit();
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment