如何合并 2 个 bzip2 压缩文件?

发布于 2024-09-07 20:18:44 字数 196 浏览 1 评论 0原文

我想合并 2 个经过 bzip2 处理的文件。我尝试将一个附加到另一个: cat file1.bzip2 file2.bzip2 > out.bzip2 似乎可以工作(该文件已正确解压缩),但我想使用该文件作为 Hadoop 输入文件,并且收到有关损坏块的错误。

合并 2 个 bzip2'ed 文件而不解压它们的最佳方法是什么?

I want to merge 2 bzip2'ed files. I tried appending one to another: cat file1.bzip2 file2.bzip2 > out.bzip2 which seems to work (this file decompressed correctly), but I want to use this file as a Hadoop input file, and I get errors about corrupted blocks.

What's the best way to merge 2 bzip2'ed files without decompressing them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

氛圍 2024-09-14 20:18:45

处理串联 bzip 已固定在主干上,或者应该是:https://issues.apache。 org/jira/browse/HADOOP-4012。有它工作的示例: https://issues.apache.org/jira/browse/MAPREDUCE-477?focusedCommentId=12871993&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel #action_12871993 确保您运行的是最新版本的 Hadoop,应该没问题。

Handling concatenated bzip is fixed on trunk, or should be: https://issues.apache.org/jira/browse/HADOOP-4012. There are examples of it working: https://issues.apache.org/jira/browse/MAPREDUCE-477?focusedCommentId=12871993&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12871993 Make sure you're running a recent version of Hadoop and you should be fine.

落花随流水 2024-09-14 20:18:45

您可以将它们都压缩(好吧,存储)到新的 bz2 中吗?这意味着您必须进行 3 次解压缩才能获取 2 个档案的内容,但可能适合您的场景。

You could compress (well, store) them both into a new bz2? It'd mean you'd have to do 3 decompressions to get the contents of the 2 archives, but might work with your scenario.

不甘平庸 2024-09-14 20:18:45

这个问题很老了,但我现在就遇到了,所以,如果其他人搜索这个问题,这就是我发现的将 HDFS 中的多个 bz2 文件合并到一个而不使用本地文件系统的方法。这也可以用于任何文本文件。

$HADOOP_HOME/bin/hadoop  jar $HADOOP_HOME/hadoop-streaming.jar \
-input foo \
-output foo_merged \
-mapper /bin/cat \
-reducer /bin/cat 

这将连接文件夹 foo 中的所有文件,并将单个文件 (part-00000) 写入文件夹 foo_merged

您可以对输入文件夹使用通配符,或根据需要使用任意数量的 -input 以包含要加入的所有文件。

输出文件将被解压缩。如果您希望输出也以 bz2 压缩,您应该指定以下两个选项:

$HADOOP_HOME/bin/hadoop  jar $HADOOP_HOME/hadoop-streaming.jar \
-D mapred.output.compress=true \
-D mapred.output.compression.codec=org.apache.hadoop.io.compress.BZip2Codec \
-input foo \
-output foo_merged \
-mapper /bin/cat \
-reducer /bin/cat 

将 BZip2Codec 替换为您想要使用的任何一个。

更多信息请参见此处

This question is quite old, but I came upon it right now, so, if anyone else searches for this, this is what I found to join multiple bz2 files in HDFS into one whithout using the local filesystem. This can be used for any text file also.

$HADOOP_HOME/bin/hadoop  jar $HADOOP_HOME/hadoop-streaming.jar \
-input foo \
-output foo_merged \
-mapper /bin/cat \
-reducer /bin/cat 

This joins all the files in folder foo and writes a single file (part-00000) to folder foo_merged.

You can use wildcards for the input folder or use as many -input as you need to include all the files that are going to be joined.

The output file will be uncompressed. If you want the output also compressed in bz2, you should specify these two options:

$HADOOP_HOME/bin/hadoop  jar $HADOOP_HOME/hadoop-streaming.jar \
-D mapred.output.compress=true \
-D mapred.output.compression.codec=org.apache.hadoop.io.compress.BZip2Codec \
-input foo \
-output foo_merged \
-mapper /bin/cat \
-reducer /bin/cat 

Replacing the BZip2Codec for whichever you want to use.

More info here.

猫弦 2024-09-14 20:18:45

您不必合并文件即可将它们用作 Hadoop 输入:

  • 考虑 file_name* - 一种模式;
  • file_name_1,file_name_2 - 输入列表。

Hadoop 会处理它。

否则,您可以使用 Hadoop 流来合并它们(通过解压缩)。

您可以按模式生成文件列表,例如:

FILES_LIST="'ls -m template*.bz2'"

INPUT_FILE="'echo $FILES_LIST | tr -d ' ' '"INPUT_FILE="'echo $FILES_LIST | tr -d ' ' '"

内部 ' 引号应该不同。您可以通过 CLI 将 $INPUT_FILE 作为变量传递给脚本。

另请考虑 CombineFileInputFormat 类作为输入格式。

You wouldn't necessary have to merge files to use them as Hadoop input:

  • consider file_name* - a pattern;
  • file_name_1,file_name_2 - list of inputs.

And Hadoop will handle it.

Otherwise you can use streaming of the Hadoop to merge them (with decompression).

You could produce list of files by pattern like:

FILES_LIST="'ls -m template*.bz2'"

INPUT_FILE="'echo $FILES_LIST | tr -d ' ' '"

inner ' quotes should be different. You can pass $INPUT_FILE as a variable to your script via CLI.

Also consider the CombineFileInputFormat class as InputFormat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文