<分区>
我是 Hadoop 的新手,对 Mapper 感到困惑参数。
以众所周知的WordCount为例:
class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> {
private Text outputKey;
private IntWritable outputVal;
@Override
public void setup(Context context) {
outputKey = new Text();
outputVal = new IntWritable(1);
}
@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
StringTokenizer stk = new StringTokenizer(value.toString());
while(stk.hasMoreTokens()) {
outputKey.set(stk.nextToken());
context.write(outputKey, outputVal);
}
}
}
查看map
函数,参数为Object key
、Text value
和Context上下文
,我是对 Object key
的样子感到困惑(你看,key
从未在 Map
函数中使用过)。
因为输入文件格式是这样的:
Deer
Beer
Bear
Beer
Deer
Deer
Bear
...
我知道 value 看起来像每一行 Deer
、Beer
等等。它们是逐行处理的。
但是 key 看起来怎么样?如何决定 key 应使用哪种数据类型?