Skip to content

Instantly share code, notes, and snippets.

@sujee
Created January 2, 2011 05:29
Show Gist options
  • Save sujee/762314 to your computer and use it in GitHub Desktop.
Save sujee/762314 to your computer and use it in GitHub Desktop.
TestMR.java : basic map reduce program that takes input path as an argument
/**
* http://sujee.net/tech/articles/amazon-emr-beyond-basics/
* takes one argument for input path
*/
public class TestMR extends Configured implements Tool
{
public static void main(String[] args) throws Exception
{
int res = ToolRunner.run(new Configuration(), new TestMR(), args);
System.exit(res);
}
@Override
public int run(String[] args) throws Exception
{
if (args.length < 1)
{
System.err.printf("Usage: %s [generic options] <input_paths>\n", getClass().getSimpleName());
ToolRunner.printGenericCommandUsage(System.err);
return -1;
}
Configuration conf = getConf();
Job job = new Job(conf, "TestMR");
job.setJarByClass(TestMR.class);
job.setMapperClass(TestMapper.class);
job.setReducerClass(TestReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setOutputFormatClass(Text.class);
FileInputFormat.addInputPath(job, args[0]);
FileInputFormat.addOutputPath(job, args[1]);
return job.waitForCompletion(true) ? 0 : 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment