いわゆる「新しい API」から CombineFileInputFormat を使用する最も簡単な方法を次に示します。実際の入力形式がMyFormatで、 MyKeyのキーとMyValueの値で動作するとします (SequenceFileInputFormat< MyKey, MyValue >
たとえば、 のサブクラスである可能性があります)。
public class CombinedMyFormat extends CombineFileInputFormat< MyKey, MyValue > {
// exists merely to fix the key/value types and
// inject the delegate format to the superclass
// if MyFormat does not use state, consider a constant instead
private static class CombineMyKeyMyValueReaderWrapper
extends CombineFileRecordReaderWrapper< MyKey, MyValue > {
protected CombineMyKeyMyValueReaderWrapper(
CombineFileSplit split, TaskAttemptContext ctx, Integer idx
) throws IOException, InterruptedException {
super( new MyFormat(), split, ctx, idx );
}
}
@Override
public RecordReader< MyKey, MyValue > createRecordReader(
InputSplit split, TaskAttemptContext ctx
) throws IOException {
return new CombineFileRecordReader< MyKey, MyValue >(
( CombineFileSplit )split, ctx, CombineMyKeyMyValueReaderWrapper.class
);
}
}
ジョブ ドライバーで、 に立ち寄ることができるようになりましCombinedMyFormat
たMyFormat
。また、最大分割サイズ プロパティを設定して、Hadoop が入力全体を 1 つの分割に結合しないようにする必要があります。