【问题标题】:Hadoop: method setMapperClass in class JobConf cannot be applied to given typesHadoop:类 JobConf 中的方法 setMapperClass 不能应用于给定类型
【发布时间】:2014-09-30 01:07:47
【问题描述】:

我对在 Java 中使用 Hadoop 框架非常陌生。我正在尝试为只有一个映射器的特定 map reduce 作业设置 JobConf(对于 reducer 没有真正的中间值)。我的映射器类在这里:

public static class GetArticlesMapper extends Mapper<LongWritable, WikipediaPage, Text, Text> 
{
    public static Set<String> peopleArticlesTitles = new HashSet<String>();

    @Override
    protected void setup(Mapper<LongWritable, WikipediaPage, Text, Text>.Context context)
            throws IOException, InterruptedException {
        // TODO: You should implement people articles load from
        // DistributedCache here
        super.setup(context);
    }

    @Override
    public void map(LongWritable offset, WikipediaPage inputPage, Context context)
            throws IOException, InterruptedException {
        // TODO: You should implement getting article mapper here
    }
}

但是,当我编译java文件时,main方法中的这一行会引发错误:

conf.setMapperClass(GetArticlesMapper.class);

上面写着:

错误:类 JobConf 中的方法 setMapperClass 不能应用于 给定类型; conf.setMapperClass(GetArticlesMapper.class); ^ 必需:类找到:类原因:实际参数 类不能通过方法调用转换为类1错误

因此我的问题是,我需要在映射器类的实现中修复什么,以便 Java 编译并且我没有收到此错误?这个问题可能措辞不佳且含糊不清,也许是因为我自己对这个主题不熟悉。我也会感谢任何 cmets 来帮助提高这个问题的质量。

【问题讨论】:

  • JobConf 是旧 API,您显示的代码是新 API。您可以使用其中任何一个继续前进。不要混合使用两者。您可以在这里找到使用新 API 的 wordcount 示例:unmeshasreeveni.blogspot.in/2014/04/…

标签: java hadoop


【解决方案1】:

您可能正在混合使用“旧 API”和“新 API”。基本上,旧 API(JobConf 是其中的一部分)位于 org.apache.hadoop.mapred 下,而新 API(使用 Job 和 Configuration 代替)位于 org.apache.hadoop.mapreduce 下。您的映射可能正在实现org.apache.hadoop.mapreduce.Mapper

有关所有差异的更多详细信息,请参见此处:http://hadoopbeforestarting.blogspot.de/2012/12/difference-between-hadoop-old-api-and.html

【讨论】:

  • 那很不幸。那么完整的 MapReduce 示例 here 使用旧的 api 呢?你知道我在哪里可以找到使用新 API 的示例(源代码,而不仅仅是 jar)。
  • 快速谷歌搜索一下这个页面:codesfusion.blogspot.sg/2013/10/… 这似乎是正确的新 API 用法。确实很烦人,那里的大多数示例都使用旧的 API - 我已经多次与这个作斗争:)
猜你喜欢
  • 2012-10-21
  • 2019-03-22
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多