Java的Hadoop FileInputFormat实现类有哪些

发布时间:2021-12-09 14:24:22 作者:iii
来源:亿速云 阅读:146

这篇文章主要讲解了“Java的Hadoop FileInputFormat实现类有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Java的Hadoop FileInputFormat实现类有哪些”吧!

思考

在运行MapReduce程序时,输入的文件格式有很多,比如:基于行的日志文件、二进制格式文件、数据库表等。那么,针对不同的数据类型,MapReduce是怎么读取这些数据的呢?

FileInputFormat常见的接口实现类包括:TextInputFormat,KeyValueTextInputFormat,NLineInputFormat,CombineTextInputFormat和自定义InputFormat等。

1.TextInputFormat

TextInputFormat是默认的FileInputFormat实现类。按行读取每条记录。键是存储该行在整个文件中的起始字节偏移量, LongWritable类型。值是这行的内容,不包括任何行终止符(换行符和回车符),Text类型。

以下是一个示例,比如,一个分片包含了如下4条文本记录。

Rich learning formIntelligent learning engineLearning more convenientFrom 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)

2.KeyValueTextInputFormat

每一行均为一条记录,被分隔符分割为key,value。可以通过在驱动类中设置conf.set(KeyValueLineRecordReader.KEY_VALUE_SEPERATOR, "\t");来设定分隔符。默认分隔符是tab(\t)。

以下是一个示例,输入是一个包含4条记录的分片。其中——>表示一个(水平方向的)制表符。

line1 ——>Rich learning formline2 ——>Intelligent learning engineline3 ——>Learning more convenientline4 ——>From the real demand for more close to the enterprise

每条记录表示为以下键/值对:

(line1,Rich learning form)(line2,Intelligent learning engine)(line3,Learning more convenient)(line4,From the real demand for more close to the enterprise)

注意:此时的键是每行排在制表符之前的Text序列。

 3.NLineInputFormat

如果使用NlineInputFormat,代表每个map进程处理的InputSplit不再按Block块去划分,而是按NlineInputFormat指定的行数N来划分。即输入文件的总行数/N=切片数,如果不整除,切片数=商+1。

以下是一个示例,仍然以上面的4行输入为例。

Rich learning formIntelligent learning engineLearning more convenientFrom the real demand for more close to the enterprise

例如,如果N是2,则每个输入分片包含两行。开启2个MapTask。

(0,Rich learning form)(19,Intelligent learning engine)

另一个 mapper 则收到后两行:

(47,Learning more convenient)(72,From the real demand for more close to the enterprise)

这里的键和值与TextInputFormat生成的一样。

感谢各位的阅读,以上就是“Java的Hadoop FileInputFormat实现类有哪些”的内容了,经过本文的学习后,相信大家对Java的Hadoop FileInputFormat实现类有哪些这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. Hadoop压缩技术的概念
  2. Hadoop 之 MapReduce

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

java hadoop

上一篇:Java的Hadoop CombineTextInputFormat小文件切片怎么理解

下一篇:Java的Hadoop KeyValueTextInputFormat怎么使用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》