2013-11-27 22 views
3

我正在學習使用hadoop並遇到以下問題: 我需要將int數組從map函數傳遞給reducer,然後作爲輸出。hadoop將int數組從地圖傳遞給reducer並作爲輸出

因此,它看起來是這樣的:

public void map(LongWritable key,Text value,OutputCollector<Text, IntWritable> output,Reporter reporter) throws IOException{ 
..snip.. 
int[] output={0,0,1,1}; //or something like it 
output.collect(word,output); 
} 

and 

public static class reduce exteds mapReduceBase implements reducer<Text,IntWritable,Text, Intwriteable>{ 
    int[] sum={0,0,0,0} 
    while(values.hasNext()){ 
    int[] numbers=values.next().get 
    for(int i=0;i<numbers.length;i++) 
     sum[i]=sum[i]+numbers[i]; 
    } 
} 

如果你知道如何解決這個問題請留言。 謝謝。

回答

1

研究編寫自己的自定義Writable(它應該很容易擴展ArrayAritable - 實際上這個類的JavaDoc有一個IntWritable數組的示例)。

相關問題