为了多次重复相同的 map/reduce 任务,我应该把循环放在哪里?我知道它应该在主程序中,我不知道它应该在周围runJob
还是其他地方?
问问题
958 次
1 回答
2
这是一个很好的例子来做你想做的事情,摘自我前段时间看到的 Thomas Jungblut 的很棒的博客:
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();
}
于 2013-01-17T00:28:55.753 回答