☆☆☆★☆☆☆

唯有努力才能活成自己想要活成的样子

导航

MapReduce处理大(小)文件的方式

1.输入大文件时

conf.setLong(FileInputFormat.SPLIT_MINSIZE,1024*1024*256L); //小于这个数据时进行合并
conf.setLong(FileInputFormat.SPLIT_MAXSIZE,1024*1024*1024); //大于这个数据时进行切分

2.输入大量小文件时

方式一:小文件先进行Merge操作再使用MapReduce

方式二:使用FileInputFormat子类CombineFileInputFormat重写RecordReader()将多个input path合并成一个InputSplit

/*
 * 实现CombineFilelnputFormat,合并小文件。
 */
public class MCombineInputFormat extends CombineFileInputFormat<ImmutableBytesWritable,KeyValue>{

    @Override
    protected boolean isSplitable(JobContext context, Path filename) {
        //return false;
        //FileInputFormat用isSplitable方法来指定对应的文件是否支持数据的切分,默认情况下都是支持的,也就是true
        return true;
    }

    @Override
    public RecordReader<ImmutableBytesWritable, KeyValue> createRecordReader(
            InputSplit split, TaskAttemptContext context) throws IOException {
        return new CombineFileRecordReader<ImmutableBytesWritable, KeyValue>((CombineFileSplit)split,context,HFileRecordReader.class);
    }

}

 

posted on 2021-06-21 17:44  Yr-Zhang  阅读(311)  评论(0编辑  收藏  举报