没有执行hadoop reduce功能?

时间:2012-06-08 21:29:34

标签: hadoop reducers

我正在运行mapreduce程序,但我意识到尽管我编写了一个reduce函数,但mapreduce并不能解决它。然后我尝试添加@Override,错误说reduce函数不会覆盖任何超级方法。

作业配置信息如下

        preProcess.setJobName("GeneProcessing program for 100 SNP");

        preProcess.setMapperClass(PreprocessMapper.class);
        preProcess.setReducerClass(PreprocessReducer.class);

        preProcess.setInputFormatClass(TextInputFormat.class);
        //setInputFormat(TextInputFormat.class);
    preProcess.setOutputFormatClass(TextOutputFormat.class);


    preProcess.setMapOutputKeyClass(Text.class);
    preProcess.setMapOutputValueClass(Text.class);  

        preProcess.setOutputKeyClass(NullWritable.class);
    preProcess.setOutputValueClass(Text.class);

    //preProcess.setNumMapTasks(4);
    preProcess.setNumReduceTasks(4);
    FileInputFormat.setInputPaths(preProcess, preprocessInputPath);
    FileOutputFormat.setOutputPath(preProcess, preprocessOutputPath);
    //JobClient.runJob(preProcess);
        preProcess.waitForCompletion(true);

减少代码如下

import java.io.*;
import java.util.*;


import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Reducer;
    public class PreprocessReducer extends Reducer<Text, Text, NullWritable, Text> 
    {
        public Text newKey = new Text("");

            //no enter the reduce task
            @Override
        protected void reduce(Text key, Iterator<Text> values, Context output)                 
             throws IOException, InterruptedException                
            {

            do something here

        }

    }

1 个答案:

答案 0 :(得分:3)

您对reduce方法的签名是错误的 - 第二个参数应该是Iterable<Text>而不是Iterator<Text>

@Override
protected void reduce(Text arg0, Iterable<Text> arg1,
         Context arg2)
         throws IOException, InterruptedException {

}

您使用的是什么IDE? Eclipse有一个Source - &gt;覆盖/实现方法菜单选项,使签名更正确。我确信Netbeans也有类似的功能。