Reputation: 6465
In order to repeat the same map/reduce task multiple times, where should I put the loop? I know it should be in the main program, what I don't know is whether it should be around runJob
or elsewhere?
Upvotes: 2
Views: 1090
Reputation: 41428
Here is a great example to do what you're trying to do, extracted from Thomas Jungblut's awesome blog which I had seen some time ago:
while (counter > 0) {
// reuse the conf reference with a fresh object
conf = new Configuration();
// set the depth into the configuration
conf.set("recursion.depth", depth + "");
job = new Job(conf);
job.setJobName("Graph explorer " + depth);
job.setMapperClass(ExplorationMapper.class);
job.setReducerClass(ExplorationReducer.class);
job.setJarByClass(ExplorationMapper.class);
// always work on the path of the previous depth
in = new Path("files/graph-exploration/depth_" + (depth - 1) + "/");
out = new Path("files/graph-exploration/depth_" + depth);
SequenceFileInputFormat.addInputPath(job, in);
// delete the outputpath if already exists
if (fs.exists(out))
fs.delete(out, true);
SequenceFileOutputFormat.setOutputPath(job, out);
job.setInputFormatClass(SequenceFileInputFormat.class);
job.setOutputFormatClass(SequenceFileOutputFormat.class);
job.setOutputKeyClass(LongWritable.class);
job.setOutputValueClass(VertexWritable.class);
// wait for completion and update the counter
job.waitForCompletion(true);
depth++;
counter = job.getCounters().findCounter(ExplorationReducer.UpdateCounter.UPDATED)
.getValue();
}
Upvotes: 2