在M / R程序中用一张地图减少

时间:2013-10-16 08:04:58

标签: hadoop mapreduce cassandra jobs

我有一个问题..如何使用一个mapper和两个reducer进行mapreduce作业,两个reducer输入都来自map输出?每个减速器都有自己的输出? 另一件事是mapper有2个或更多输入吗?

public static class dpred extends Reducer<Text, DoubleWritable, Text, DoubleWritable>
 {
   public void reduce1(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException
    {
        double beta = 17.62;
        DoubleWritable result1 = new DoubleWritable();
        double mul = 1;
        double res = 1;
         for (DoubleWritable val : values){
         //  System.out.println(val.get());
           mul *= val.get();
           }             
         res = beta*mul;
         result1.set(res);
         context.write(key, result1);
     }

///////////////////////////////////////////////////////////

public void reduce2(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException
{
    double landa = 243.12;
    double sum = 0;
    double res = 0;
    DoubleWritable result2 = new DoubleWritable();
     for (DoubleWritable val : values){
     //  System.out.println(val.get());
       landa += val.get();
       }
    // System.out.println(sum);
     result2.set(landa);
     context.write(key, result2);
   }
 }

1 个答案:

答案 0 :(得分:1)

如果操作很简单,你可以考虑在一次reduce函数中做2个context.write()(如果你愿意,可以用MultipleOutputs将它们写入不同的文件)