如何将 HDFS 目录中的所有文件合并到一个压缩文件中, 无需通过本地计算机复制数据?例如,但不一定,使用 Pig?
例如,我有一个文件夹/data/input,其中包含文件 part-m-00000.gz 和 part-m-00001.gz。现在我想将它们合并成一个文件/data/output/foo.gz
最佳答案
我建议查看 FileCrush ( https://github.com/edwardcapriolo/filecrush ),这是一种使用 MapReduce 合并 HDFS 上文件的工具。它完全按照您的描述进行操作,并提供了多个选项来处理压缩和控制输出文件的数量。
Crush --max-file-blocks XXX /data/input /data/output
max-file-blocks
表示每个输出文件的最大 dfs block 数。例如,根据文档:
With the default value 8, 80 small files, each being 1/10th of a dfs block will be grouped into to a single output file since 8 * 1/10 = 8 dfs blocks. If there are 81 small files, each being 1/10th of a dfs block, two output files will be created. One output file contain the combined contents of 41 files and the second will contain the combined contents of the other 40. A directory of many small files will be converted into fewer number of larger files where each output file is roughly the same size.
关于hadoop - 合并 HDFS 上的压缩文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30078945/