2012-02-25 28 views
0

我正嘗試在Reducer中使用MultipleOutputs,以便使用分區程序寫入多個文件。對於這一點,我想構建使用Reducer.setup()的對象,如下所示:有關MultipleOutputs for Hadoop的查詢0.20.203

public static class MOReduce extends Reducer<Text, Integer, Text, Integer> { 
    private MultipleOutputs mos; 

    public void setup(Reducer.Context context) { 
     mos = new MultipleOutputs(context.getConfiguration()); 
    } 

但我面對的是因爲以下問題:

  • 按照該documentation,設置功能需要Reducer.Context作爲參數
  • 而按照此documentation,MultipleOutputs構造函數需要JobConf。所以,基本上我就沒有辦法從Reducer.Context
  • 我已經嘗試過像Reducer.Context.getConfXXX返回JobConf任何函數提取JobConf但只有一個功能getConfiguration()返回JobContext

那麼,你能否建議我如何解決這個問題並實例化MultipleOutputs對象。

回答

0

看一看這個Multiple Output in Reducer

有兩種API在Hadoop中創建和管理MapReduce作業。一個是JobConf,另一個是Job。你似乎在使用Job。對於你的情況,如上面的鏈接,你需要創建自己的RecordWriter類和OutputFormat類。通過RecordWriter,您可以控制要寫入哪些文件以及何時寫入。

+0

謝謝拉維。我會嘗試。 – 2012-02-26 00:18:45