资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Java的HadoopFileInputFormat实现类有哪些

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

创新互联建站凭借专业的设计团队扎实的技术支持、优质高效的服务意识和丰厚的资源优势,提供专业的网站策划、网站建设、成都做网站、网站优化、软件开发、网站改版等服务,在成都十载的网站建设设计经验,为成都上1000+中小型企业策划设计了网站。

思考

在运行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实现类有哪些这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


网站栏目:Java的HadoopFileInputFormat实现类有哪些
转载来源:http://cdkjz.cn/article/jiodge.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220