ファイルの順序は重要であり、辞書順では目的を達成できないため、このタスク用のマッパー プログラムを作成することをお勧めします。これはおそらく定期的に実行できます。もちろん、リデューサーはありません。これを HDFS マップ タスクとして記述すると、データ ノード間であまりデータを移動せずにこれらのファイルを 1 つの出力ファイルにマージできるため、効率的です。ソース ファイルは HDFS にあり、マッパー タスクはデータ アフィニティを試行するため、異なるデータ ノード間でファイルを移動することなくファイルをマージできます。
マッパー プログラムには、カスタム InputSplit (入力ディレクトリ内のファイル名を取得し、必要に応じて並べ替える) とカスタム InputFormat が必要です。
マッパーは、hdfs 追加、または byte[] に書き込むことができる未加工の出力ストリームのいずれかを使用できます。
私が考えている Mapper プログラムの大まかなスケッチは次のようなものです。
public class MergeOrderedFileMapper extends MapReduceBase implements Mapper<ArrayWritable, Text, ??, ??>
{
FileSystem fs;
public void map(ArrayWritable sourceFiles, Text destFile, OutputCollector<??, ??> output, Reporter reporter) throws IOException
{
//Convert the destFile to Path.
...
//make sure the parent directory of destFile is created first.
FSDataOutputStream destOS = fs.append(destFilePath);
//Convert the sourceFiles to Paths.
List<Path> srcPaths;
....
....
for(Path p: sourcePaths) {
FSDataInputStream srcIS = fs.open(p);
byte[] fileContent
srcIS.read(fileContent);
destOS.write(fileContent);
srcIS.close();
reporter.progress(); // Important, else mapper taks may timeout.
}
destOS.close();
// Delete source files.
for(Path p: sourcePaths) {
fs.delete(p, false);
reporter.progress();
}
}
}