【问题标题】:MapReduceBase and Mapper deprecated不推荐使用 MapReduceBase 和 Mapper
【发布时间】:2011-11-29 09:03:21
【问题描述】:
public static class Map extends MapReduceBase implements Mapper

MapReduceBaseMapperJobConfHadoop 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 会说明你应该使用什么。

标签: java hadoop mapreduce


【解决方案1】:

functionality 在新旧 API 之间没有太大区别,只是旧 API 支持推送到 map/reduce 函数,而新 API 支持 both push and pull API。虽然,新的 API 更加简洁且易于发展。

这里是JIRA,用于介绍新的 API。此外,旧 API 在 0.21 中为 un-deprecated,将在 release 0.22 or 0.23 中弃用。

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

【讨论】:

    【解决方案2】:

    Javadoc 包含在这个过时的类中使用什么的信息:

    例如http://hadoop.apache.org/common/docs/current/api/org/apache/hadoop/mapred/JobConf.html

     Deprecated. Use Configuration instead
    

    编辑:当你使用 maven 和开放类声明 (F3) 时,maven 可以自动下载源代码,你会看到带有解释的 javadoc cmets 的内容。

    【讨论】:

    • + 1 表示配置。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 2012-11-14
    • 1970-01-01
    • 2019-11-08
    • 2019-11-08
    • 2020-01-03
    相关资源
    最近更新 更多