Skip to content

Instantly share code, notes, and snippets.

@ebrucucen
Last active February 16, 2021 08:54
Show Gist options
  • Save ebrucucen/fa32fece01f93f165b142091dc02a4ac to your computer and use it in GitHub Desktop.
Save ebrucucen/fa32fece01f93f165b142091dc02a4ac to your computer and use it in GitHub Desktop.
java example for mapreduce
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: ratemovie <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "rate movie");
job.setJarByClass(MovieRating.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
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