2014-09-30 384 views
0

我對於在Java中使用Hadoop框架非常新穎。我正在嘗試設置JobConf用於只有映射器的特定映射縮減作業(Reducer沒有真正的中間值)。我的映射類是在這裏:Hadoop:類JobConf中的setMapperClass方法不能應用於給定的類型

conf.setMapperClass(GetArticlesMapper.class); 

它說:

error: method setMapperClass in class JobConf cannot be applied to given types; conf.setMapperClass(GetArticlesMapper.class); ^ required: Class found: Class reason: actual argument Class cannot be converted to Class by method invocation conversion 1 error

因此我

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文件,此行的主要方法將引發錯誤問題是,我需要在我的映射器類的實現中修復以便Java編譯並且不會出現此錯誤?這個問題可能措辭不明確,可能是因爲我對這個問題不熟悉。我會很感激任何意見,以幫助提高這個問題的質量。

+0

JobConf是舊的API,並且您顯示的代碼是新的API。您可以使用任何一個前進。不混合兩者。你可以在這裏找到使用新API的wordcount示例:http://www.unmeshasreeveni.blogspot.in/2014/04/hadoop-wordcount-example-in-detail.html – 2014-09-30 03:55:14

回答

3

您可能在混合使用「舊API」和「新API」。基本上,舊的API(其中JobConf是其中一部分)生活在org.apache.hadoop.mapred之下,新的API(使用作業和配置)取代org.apache.hadoop.mapreduce。您的映射可能正在實施org.apache.hadoop.mapreduce.Mapper

關於所有差異的更多細節可以在這裏找到:http://hadoopbeforestarting.blogspot.de/2012/12/difference-between-hadoop-old-api-and.html

+0

這是不幸的。完全充實的MapReduce示例[這裏](http://hadoop.apache.org/docs/r1.2.1/mapred_tutorial.html)使用舊的api呢?你知道我在哪裏可以找到一個使用新API的例子(源代碼,而不僅僅是jar)。 – user3898238 2014-09-30 02:25:28

+0

一個快速的谷歌提到了這個頁面:http://codesfusion.blogspot.sg/2013/10/hadoop-wordcount-with-new-map-reduce-api.html這似乎是正確的新的API使用。確實非常煩人的是,大部分的例子都使用舊的API--我已經與這個很多次:) – xpa1492 2014-09-30 02:43:37

相關問題