InputFormat切片

**

处理数据时怎么完成切片的?

**
inpt -> inputFormat -> map ->shuffle -> reduce -> outputformat -> 本地文件
默认私用的是TextInputFormat

getSplits():切片方法
isSplitable(job, path):判断文件是否支持切片,根据文件路径获取压缩格式,如果支持切片返回true,如果文件不是压缩文件,则直接返回true
file.getBlockSize();获取块大小
Math.max(minSize, Math.min(maxSize, blockSize)):获取切片的大小
当需要让切片的大小小于块大小的时,要调整maxsize
当需要让切片的大小大于块大小的时,要调整minsize
默认的切片大小时128M
long bytesRemaining = length;
while (((double) bytesRemaining)/splitSize > SPLIT_SLOP) {
int blkIndex = getBlockIndex(blkLocations, length-bytesRemaining);
splits.add(makeSplit(path, length-bytesRemaining, splitSize,
blkLocations[blkIndex].getHosts(),
blkLocations[blkIndex].getCachedHosts()));
bytesRemaining -= splitSize;
}

####hadoop系统自带的inputFormat类型
inputFormat:把文件内容转换成key,value值
默认使用的是TextInputFormat
InputFormat<?, ?> input =
ReflectionUtils.newInstance(job.getInputFormatClass(), conf);

TextInputFormat extends FileInputFormat<LongWritable, Text>
TextInputFormat:没有重写切片方法getSplits,默认使用的时FileInputFormat的切片方法
返回:LineRecordReader -> LongWritable, Text

NLineInputFormat: NLineInputFormat extends FileInputFormat<LongWritable, Text>
NLineInputFormat:重写了getSplits方法,默认按照行进行切片
返回:LineRecordReader -> LongWritable, Text

CombineFileInputFormat: CombineFileInputFormat<K, V> extends FileInputFormat
CombineTextInputFormat extends CombineFileInputFormat<LongWritable,Text>
CombineFileInputFormat:重写了getSplits方法,自定义切片的大小
返回的是:CombineFileRecordReader ->LongWritable,Text

KeyValueTextInputFormat:KeyValueTextInputFormat extends FileInputFormat<Text, Text>
KeyValueTextInputFormat:没有重写切片方法getSplits,默认使用的时FileInputFormat的切片方法
返回的是:KeyValueLineRecordReader -> Text, Text

SequenceFileInputFormat<K, V> extends FileInputFormat<K, V>
SequenceFileInputFormat:没有重写切片方法getSplits,默认使用的时FileInputFormat的切片方法
返回的是:SequenceFileRecordReader -> Text, Text

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值