将多个序列文件合并到Hadoop中的一个序列文件中

cld*_*ldo 5 hadoop mapreduce

如何在Hadoop中将多个序列文件合并为一个序列文件谢谢.

sau*_*ank 5

If you want to merge multiple files into single file then here is two ans :

Native language


getmerge
Run Code Online (Sandbox Code Playgroud)

Usage: hadoop fs -getmerge <src> <localdst>

Takes a source directory and a destination file as input and concatenates files in src into the destination local file. Optionally addnl can be set to enable adding a newline character at the end of each file.



Java API


org.apache.hadoop.fs.FileUtil.copyMerge(FileSystem srcFS, Path srcDir, FileSystem dstFS, Path dstFile, boolean deleteSource, Configuration conf, String addString);
Run Code Online (Sandbox Code Playgroud)

Copy all files in a directory to one output file (merge)

Copy to hdfs

put
Run Code Online (Sandbox Code Playgroud)

Usage: hadoop dfs -put <localsrc> ... <dst>

将单个 src 或多个 src 从本地文件系统复制到目标文件系统。还从 stdin 读取输入并写入目标文件系统。

copyFromLocal
Run Code Online (Sandbox Code Playgroud)

用法: hadoop dfs -copyFromLocal <localsrc> URI

类似于 put 命令,除了源被限制为本地文件引用。

  • 是的,`getmerge` 从字面上连接输入文件的字节。这适用于文本文件,但对于序列文件,您需要智能键值合并。最重要的是,您不希望将一个文件的标题复制到另一个文件中,然后将其解释为记录条目。 (4认同)
  • 我获取本地文件,然后将文件放入 hdfs。然后在此文件中运行 hadoop 作业。错误是:java.io.IOException:文件已损坏!在 org.apache.hadoop.io.SequenceFile$Reader.readBlock(SequenceFile.java:第1734章 (3认同)

Don*_*ner 3

如果您正在处理大量序列文件,我建议编写一个 MapReduce 作业,将其用作Mapper映射器和Reducer化简器。对于 I/O 格式,使用SequenceFileInputFormatSequenceFileOutputFormat将减速器的数量设置为 1。这些都是您在驱动程序/主代码的配置和作业对象中设置的内容。了解如何设置输出格式如何设置输入格式如何设置映射器以及如何设置化简器

Mapper请注意,和的默认行为Reducer是不对数据执行任何操作 - 只是将其传递。这就是为什么你不在这里编写map函数或reduce函数。

这样做的作用是加载序列文件,不对映射器中的数据执行任何操作,将所有记录混洗到减速器,然后将它们全部输出到一个文件。这确实会对输出序列文件中的键进行排序产生副作用。