Hadoop应用程序找不到Reducer

时间:2015-07-01 11:49:22

标签: java hadoop hbase reducers

我正在尝试创建一个mapreduce应用程序,该应用程序从Hbase表中读取并将作业结果写入文本文件中。我的驱动程序代码如下所示:

    Configuration conf = HBaseConfiguration.create();
    Job job = Job.getInstance (conf, "mr test");
    job.setJarByClass(Driverclass.class);
    job.setCombinerClass(reducername.class);
    job.setReducerClass(reducername.class);

    Scan scan = new Scan();
    scan.setCaching(500);            
    scan.setCacheBlocks(false);        

    String qualifier = "qualifname"; // comma seperated
    String family= "familyname";
    scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));

    TableMapReduceUtil.initTableMapperJob("tablename", 
                                           scan, 
                                           mappername.class, 
                                           Text.class, Text.class, 
                                           job);

当调用initTableMapperJob时,我得到一个ClassNotFoundException:找不到类reducername。

该类在另一个java文件中定义,位于同一个包中。我使用几乎相同的配置来尝试通常的wordcount示例并且工作正常。然后我改变了mapper的类型及其配置方式,我得到了这个错误。有人能帮助我吗?

编辑:reducer类的代码是:

package mr.roadlevelmr;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Reducer;
public class reducername extends Reducer <Text, Text, Text, Text>{
    private Text result= new Text();

    public void reduce (Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException{
       ArrayList<String> means = new ArrayList<String>();
        for (Text val : values){
            means.add(String.valueOf(val.getBytes()));
        }
        result.set(newMean(means));
        context.write(key, result);
    }

1 个答案:

答案 0 :(得分:2)

你应该使用Map reduce util,如下所示:

TableMapReduceUtil.initTableMapperJob("tablename", 
                                       scan, 
                                       mappername.class, 
                                       Text.class, Text.class, 
                                       job);Ok think I found the issue! 

而不是添加reducer和combiner

job.setCombinerClass(reducername.class);
job.setReducerClass(reducername.class);
boolean b = job.waitForCompletion(true);

而不是将reducer添加到表映射器作业