2013-01-16 55 views
0

我有一個映射新手Hadoop的..分佈式緩存

public class BuildGraph{ 
    public void config(JobConf job){ <==this block doesnt seems to be exexcuting at all :(
    super.configure(job); 
    this.currentId = job.getInt("currentId",0); 
    if (this.currentId!=0){ 
    // I call a method from differnt class to build a distributed cache 
    } 
    } 
    public void map(....){ 
.... 
} 

}

現在主要的代碼,其中這被稱爲..

public void run(String params,curId){ 
JobConf conf = new JobConf(classname.class); 
conf.setInt("currentId",299); <--note this i am setting the value here 
conf.setMapperClass(BuildGraph.class); 
//.... 
    JobClient.runJob(conf); 
} 

但問題是,在配置方法代碼沒有執行,就像「currentId」在主循環中返回299一樣,但它在映射器類中根本沒有設置。 我在做什麼錯

鏈接到完整的代碼 http://pastebin.com/DRPXUm62

回答

1

看起來你沒有使用正確的合同,因爲你不延長MapReduceBase和不執行Mapper。該方法也應該被稱爲configure而不是config。嘗試這樣的事情:

public class BuildGraph extends MapReduceBase implements Mapper<K, V, K, V> { 
    public void configure(JobConf job) { 
     // this will get called once at the beginning of the task 
    } 

    public void map(...) { 
     ... 
    } 
} 
+0

我改正了它,但仍然是相同的問題。 – Fraz

+0

@Fraz你可以發佈你的完整的映射代碼和主?如果太大,您可以鏈接到外部文本編輯器 –

+0

這裏是鏈接 http://pastebin.com/DRPXUm62 – Fraz