MapReduceBase和Mapper已废弃。

10
public static class Map extends MapReduceBase implements Mapper

MapReduceBase类、Mapper接口和JobConf类已经在Hadoop 0.20.203中被弃用。

现在应该使用什么?

编辑1 - 对于MapperMapReduceBase,我们只需要继承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会说明你应该使用哪个替代方法。 - rossum
2个回答

7

+1 用于配置。谢谢。 - JohnJohnGa

4

新旧API在功能上没有太大区别,除了旧API支持将数据推送到map/reduce函数,而新API支持推送和拉取API。虽然新API更加简洁易用。

这里是新API介绍的JIRA链接。同时,旧API已在0.21版本中取消弃用标记,并将在0.22或0.23版本中弃用。

您可以在这里这里找到有关新API或有时称为“上下文对象”的更多信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接