【问题标题】:merge output of mapreduce into another directory structure将 mapreduce 的输出合并到另一个目录结构中
【发布时间】:2013-11-07 15:52:12
【问题描述】:
我的mapreduce 作业当前使用multipleoutputs (as explained here) 生成以下结构的输出:
2013
01
02
..
2012
01
02
..
输出的基本路径是/dev/project/job1/output
但是,另一个作业(job2)生成类似的数据,我希望这个作业(job1)的输出与另一个作业(job2)的输出合并。
我正在尝试将生成的输出合并到一个公共输出目录(/dev/project/combinedoutput),其中包含上述结构以及两个作业的组合输出。有没有办法在不手动运行 shell 命令的情况下在作业本身中做到这一点?
欣赏任何见解。
【问题讨论】:
标签:
hadoop
mapreduce
hdfs
【解决方案1】:
在工作本身?不是真的,但是你可以在作业完成后在 main 函数中这样做
//prior code above
job.waitForCompletion(true);
FileSystem fs = FileSystem.get(conf);
String job1Dir = "/dev/project/job1/output";
String combinedDir = "(/dev/project/combinedoutput";
Path job1Path = new Path(job1Dir+*/);
FileStatus[] job1Files = fs.globStatus(job1Path);
for(file: job1Files){
if(file.isFile()){
String fullFileName = file.getPath().toString();
String belowMainDir = fullFileName.subString(job1Dir.length());
String newFileName = combinedDir+belowMainDir+"job1";
fs.mkdirs(new Path(newFileName.subString(0,lastIndexOf("/")));
fs.rename(file.getPath(),new Path(combinedDir+belowMainDir+"job1");
}
}
这应该会让你的文件移动过来。对 job2 做同样的事情,你应该被设置。或者,您可以更改代码,使其复制而不是重命名,和/或在您完成后删除原始的 job1/job2 目录。