在mapreduce中,每个reduce任务将其输出写入名为part-r-nnnnn的文件,其中nnnnn是与reduce任务关联的分区ID.map/reduce是否合并这些文件?如果有,怎么样?
dil*_*iop 119
您可以通过调用以下命令来委托reduce输出文件的整个合并,而不是自己合并文件.
hadoop fs -getmerge /output/dir/on/hdfs/ /desired/local/output/file.txt
Run Code Online (Sandbox Code Playgroud)
注意这会在本地组合HDFS文件.确保在运行之前有足够的磁盘空间
Nie*_*jes 28
不,这些文件不会被Hadoop合并.您获得的文件数与reduce任务数相同.
如果您需要它作为下一个作业的输入,那么不要担心有单独的文件.只需将整个目录指定为下一个作业的输入.
如果确实需要群集外的数据,那么我通常会在从群集中提取数据时将它们合并到接收端.
就是这样的:
hadoop fs -cat /some/where/on/hdfs/job-output/part-r-* > TheCombinedResultOfTheJob.txt
Run Code Online (Sandbox Code Playgroud)
小智 8
这是您可以用于在HDFS中合并文件的功能
public boolean getMergeInHdfs(String src, String dest) throws IllegalArgumentException, IOException {
FileSystem fs = FileSystem.get(config);
Path srcPath = new Path(src);
Path dstPath = new Path(dest);
// Check if the path already exists
if (!(fs.exists(srcPath))) {
logger.info("Path " + src + " does not exists!");
return false;
}
if (!(fs.exists(dstPath))) {
logger.info("Path " + dest + " does not exists!");
return false;
}
return FileUtil.copyMerge(fs, srcPath, fs, dstPath, false, config, null);
}
Run Code Online (Sandbox Code Playgroud)
仅对于文本文件和HDFS作为源和目标,请使用以下命令:
hadoop fs -cat /input_hdfs_dir/* | hadoop fs -put - /output_hdfs_file
这将连接所有文件,input_hdfs_dir并将输出写回HDFS output_hdfs_file.请记住,所有数据都将被带回本地系统,然后再次上传到hdfs,尽管没有创建临时文件,这使用UNIX pe即时发生.
此外,这不适用于非文本文件,如Avro,ORC等.
对于二进制文件,您可以执行类似的操作(如果您在目录上映射了Hive表):
insert overwrite table tbl select * from tbl
根据您的配置,这可能还会创建多个文件.要创建单个文件,请将reducers的数量设置为1,mapreduce.job.reduces=1或将hive属性设置为hive.merge.mapredfiles=true.
| 归档时间: |
|
| 查看次数: |
71662 次 |
| 最近记录: |