【发布时间】:2011-11-29 09:03:21
【问题描述】:
public static class Map extends MapReduceBase implements Mapper
MapReduceBase、Mapper 和 JobConf 在 Hadoop 0.20.203 中已弃用。
我们现在应该使用什么?
编辑 1 - 对于 Mapper 和 MapReduceBase,我发现我们只需要扩展 Mapper
public static class Map extends Mapper
<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
编辑 2 - 对于JobConf,我们应该使用如下配置:
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf);
job.setMapperClass(WordCount.Map.class);
}
编辑 3 - 我根据新 API 找到了一个很好的教程:http://sonerbalkir.blogspot.com/2010/01/new-hadoop-api-020x.html
【问题讨论】:
-
文档说你应该使用什么?通常,当某些东西被弃用时,Javadoc 会说明你应该使用什么。