2

我正在运行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

        }

    }
4

1 回答 1

3

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

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

}

你用的是什么IDE?Eclipse 有一个 Source -> Override / Implement 方法菜单选项,这使得签名正确变得更加容易。我确信 Netbeans 具有类似的功能。

于 2012-06-08T22:32:31.513 回答