【问题标题】:hadoop passing int array from map to reducer and as outputhadoop将int数组从map传递到reducer并作为输出
【发布时间】:2013-11-27 08:02:41
【问题描述】:

我正在学习使用 hadoop 并遇到以下问题: 我需要将一个 int 数组从 map 函数传递给 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]; 
  }
}

如果您知道如何解决此问题,请发布。 谢谢。

【问题讨论】:

    标签: java arrays hadoop int cloudera


    【解决方案1】:

    考虑编写自己的custom Writable(扩展ArrayWritable 应该很容易——事实上,此类的JavaDoc 有一个IntWritable 数组的示例)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 2015-08-28
      • 2012-10-06
      • 1970-01-01
      相关资源
      最近更新 更多