Hadoop的InputFormat和OutputFormat

本文深入探讨了MapReduce框架中InputFormat和OutputFormat的作用,详细解释了InputSplit的概念及其在数据输入过程中的角色,同时介绍了如何将不同类型的输入数据转化为Map能处理的键值对形式。此外,文章还概述了OutputFormat的功能,强调了其在数据输出阶段的重要性,包括验证输出规格和提供用于写入输出文件的RecordWriter实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一 InputFormat概述:

(1)InputFormat类:InputFormat用来描述和控制MapReduce Job的数据输入。



(2)InputSplit(输入分片):代表分配给单个map任务的数据。InputSplit存储的并非数据本身,而是一个分片长度和一个记录数据位置的数组,生成InputSplit的方法可通过InputFormat来设置。InputFormat的getSplits方法可以生成InputSplit相关信息,包括两部分:InputSplit元数据信息和原始InputSplit信息。InputSplit元数据信息将被JobTracker使用,用以生成Task本地性相关数据结构;原始InputSplit信息将被Map Task初始化时使用,用以获取自己要处理的数据。


(3)map任务处理的数据是由InputFormat分解过的数据,InputFormat将数据集分割为输入分片(InputSplit)。map会将分片传送给InputFormat,InputFormat调用getRecordReader方法生成RecordReader,RecordReader再通过createKey、createValue方法创建可供Map处理的<key,value>。


(4)Hadoop预定义了多种方法将不同类型输入数据转化为Map能处理的<key,value>对(也可自定义),它们都继承自InputFormat,分别是:

*DBInputFormat

*DelegatingInputFormat

*FIleInputFormat:CombineFileInputFormat, KeyValueTextInputFormat, NLineInputFormat,SequenceFileInputFormat, TextInputFormat。


二 OutputFormat概述:

(1)OutputFormat类:OutputFormat类描述和控制MapReduce Job的数据输出。

(2)MapReduce框架需要OutputFormat做的工作:

*Validate the output-specification of the job. For e.g. check that the output directory doesn't already exist.
*Provide the RecordWriter implementation to be used to write out the output files of the job. Output files are stored in a FileSystem.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值