我知道shell中的“getmerge”命令可以完成这项工作。
但是,如果我想在作业之后通过HDFS API for java合并这些输出,该怎么办?
我真正想要的是HDFS上的单个合并文件。
我唯一能想到的就是在那之后开始一项额外的工作。
谢谢!
答案 0 :(得分:10)
但是,如果我想在作业之后通过HDFS API for java合并这些输出,该怎么办?
猜测,因为我自己没有尝试过,但我认为您正在寻找的方法是FileUtil.copyMerge,这是FsShell在运行-getmerge
命令时调用的方法。 FileUtil.copyMerge
将两个FileSystem对象作为参数--FsShell使用FileSystem.getLocal来检索目标FileSystem,但我没有看到任何理由您不能在目标上使用Path.getFileSystem来获取OutputStream
那就是说,我认为它不会让你获胜 - 合并仍在本地JVM中进行;所以你并没有真正节省-getmerge
,而是-put
。
答案 1 :(得分:4)
您可以通过在代码中设置单个Reducer来获得单个输出文件。
Job.setNumberOfReducer(1);
将满足您的要求,但代价
或
Static method to execute a shell command.
Covers most of the simple cases without requiring the user to implement the Shell interface.
Parameters:
env the map of environment key=value
cmd shell command to execute.
Returns:
the output of the executed command.
org.apache.hadoop.util.Shell.execCommand(String[])