Hadoop Mapper参数含义

问题描述 投票:1回答:1

我是Hadoop的新手并且对参数有疑问:对于单词计数示例,请参阅下面的代码片段:

public static class TokenizerMapper
   extends Mapper<LongWritable, Text, Text, IntWritable> {

   .....

   public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 
   {
       .......
   }
}

我知道“value”参数是从文件读取的行,但“key”参数是什么意思?它对应的是什么?

为什么它的类型是LongWritable?

通过搜索文档我浪费了几个小时,有人可以帮忙吗?

hadoop mapreduce mapper
1个回答
2
投票

关键是LongWritable类型,因为wordcount程序将输入作为TextInputFormat

根据JavDocTextInputFormat

纯文本文件的InputFormat。文件分为几行。换行或回车用于发出行尾信号。键是文件中的位置,值是文本行。

根据定义,假设你的文字是

We are fine.
How are you?
All are fine.

然后输入到映射器

关键:1价值:We are fine.

键:14值:How are you?(第一行包含换行符约13个字符,因此行位置为14)

键:28值:All are fine.(第二行中还有大约13个字符,包括换行符,因此自文件开头以来的行位置为28)

© www.soinside.com 2019 - 2024. All rights reserved.