java Hadoop映射器参数解释
我是Hadoop的新手,对Mapper参数感到困惑
以众所周知的字数为例:
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 context
,我对Object key
看起来像什么感到困惑(你看,key
从未在Map
函数中使用过)
由于输入文件格式如下:
Deer
Beer
Bear
Beer
Deer
Deer
Bear
...
我知道值看起来像每一行Deer
、Beer
,等等。它们是逐行处理的
但是键看起来怎么样?如何决定应使用哪种数据类型的键
# 1 楼答案
这里的一切都取决于所使用的
InputFormat
类。它解析输入数据源并为您提供(键、值)对。不同的输入格式实现可以为您提供不同的流,即使具有相同的输入源以下是一篇演示该方法的文章:
https://hadoopi.wordpress.com/2013/05/31/custom-recordreader-processing-string-pattern-delimited-records/
这里的主要驱动程序是
RecordReader