TextInputFormat切片机制
一、TextInputFormat
- TextInputFormat是默认的FileInputFormat实现类。按行读取每条记录。键是存储该行在整个文件中的起始字节偏移量, LongWritable类型。值是这行的内容,不包括任何行终止符(换行符和回车符),Text类型。
以下是一个示例,比如,一个分片包含了如下4条文本记录。
Rich learning form
Intelligent learning engine
Learning more convenient
From the real demand for more close to the enterprise
每条记录表示为以下键/值对:
(0,Rich learning form)
(19,Intelligent learning engine)
(47,Learning more convenient)
(72,From the real demand for more close to the enterprise)
相关链接:FileInputFormat切片源码解析 https://blog.csdn.net/weixin_42796403/article/details/109804581
二、源码解析
TextInputFormat(默认使用的类)
/*
该类重写了createRecordReader方法并返回了LineRecordReader的对象
LineRecordReader:是真正用来读取数据的(默认的)一行一行读取数据。
*/
@Override
public RecordReader<LongWritable, Text>
createRecordReader(InputSplit split,
TaskAttemptContext context) {
return new LineRecordReader(recordDelimiterBytes);
}