Hadoop源码学习之-----Mapreduce输入流:InputFormat,InputSplit,RecordReader

本文介绍了MapReduce中输入流的基本概念,包括抽象类InputSplit和InputFormat的作用,以及如何通过FileInputFormat和TextInputFormat实现文件的拆分和记录读取。重点讲解了计算SplitFile大小的方法及LineRecordReader的具体实现。

Mapreduce 输入流

这里写图片描述

abstract class inputSplit

abstract class InputFormat:

getSplits : split the input files/db/sequecefiles
createRecordReader  : return the RecordReader of one of split of splits

FileInputFormat

TextInputFormat extends FileInputFormat

//计算SplitFile的大小
  protected long computeSplitSize( long blockSize , long minSize,
                                  long maxSize ) {
    return Math.max(minSize , Math.min( maxSize, blockSize));

createRecordReader:

    String delimiter = context.getConfiguration().get(
        "textinputformat.record.delimiter" );
    byte[] recordDelimiterBytes = null ;
    if (null != delimiter)
      recordDelimiterBytes = delimiter.getBytes(Charsets. UTF_8);
    return new LineRecordReader(recordDelimiterBytes );

LineRecordReader:

    // We always read one extra line, which lies outside the upper
    // split limit i.e. (end - 1)
    while (getFilePosition() <= end || in.needAdditionalRecordAfterSplit()) {

LineReader:

  private int bufferSize = DEFAULT_BUFFER_SIZE;
  private InputStream in;
  private byte[] buffer ;
  private int readCustomLine(Text str, int maxLineLength , int maxBytesToConsume)
    //一个一个buffer读
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值