【问题标题】:New to Hadoop MapReduce, getting a NoSuchMethodException on mapred.Reducer.<init>()Hadoop MapReduce 新手,在 mapred.Reducer.<init>() 上获得 NoSuchMethodException
【发布时间】:2012-08-14 22:05:54
【问题描述】:

解决方案:使用更好的教程-http://hadoop.apache.org/mapreduce/docs/r0.22.0/mapred_tutorial.html

我刚开始使用 MapReduce,遇到了一个奇怪的错误,我无法通过 Google 回答。我正在制作一个基本的 WordCount 程序,但是当我运行它时,在 Reduce 期间出现以下错误:

java.lang.RuntimeException: java.lang.NoSuchMethodException: org.apache.hadoop.mapred.Reducer.<init>()
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
at org.apache.hadoop.mapred.ReduceTask.runOldReducer(ReduceTask.java:485)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:420)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
at org.apache.hadoop.mapred.Child.main(Child.java:249)

WordCount 程序是 Apache MapReduce 教程中的一个。我在 Mountain Lion 上以伪分布式模式运行 Hadoop 1.0.3,我认为所有这些都运行良好,因为示例都正常执行。有什么想法吗?

编辑:这是我的参考代码:

package mrt;

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

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;

public class WordCount {
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(LongWritable key, Text value, OutputCollector<Text,IntWritable> output, Reporter reporter)
      throws IOException{

        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while(tokenizer.hasMoreTokens()){
            word.set(tokenizer.nextToken());
            output.collect(word,one);
        }
    }
}

public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {

    public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter)
      throws IOException{

        int sum = 0;

        while(values.hasNext()){
            sum += values.next().get();
        }

        output.collect(key, new IntWritable(sum));

    }
}

public static void main(String[] args) throws Exception{

    JobConf conf = new JobConf(WordCount.class);
    conf.setJobName("Wordcount");

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);

    conf.setMapperClass(Map.class);
    conf.setCombinerClass(Reduce.class);
    conf.setReducerClass(Reducer.class);

    conf.setInputFormat(TextInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    FileInputFormat.setInputPaths(conf, new Path(args[0]));
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));

    JobClient.runJob(conf);

}
}

【问题讨论】:

    标签: java apache hadoop mapreduce nosuchmethoderror


    【解决方案1】:

    问题不在于您选择的 API。完全支持稳定的 (mapred.*) 和不断发展的 (mapreduce.*) API,并且框架本身对这两种 API 进行了测试,以确保版本之间不会出现回归/损坏。

    问题出在这一行:

    conf.setReducerClass(Reducer.class);
    

    当您应该设置 Reducer 接口的实现时,您正在将 Reducer 接口设置为 Reducer。将其更改为:

    conf.setReducerClass(Reduce.class);
    

    会解决的。

    【讨论】:

      【解决方案2】:

      检查以确保您使用的是 hadoop.mapreduce 包而不是 hadoop.mapred 包。与当前版本的 mapreduce 类相比,mapred 包较旧,并且在类上具有不同的方法。

      【讨论】:

      • 我目前正在使用 hadoop.mapred 包,因为这是教程使用的。切换到 hadoop.mapreduce 会导致 MapReduceBase、Mapper、Reducer 等出现错误。开关是必要的,还是 hadoop.mapred 仍然可以工作?
      • 包的使用需要在单个作业中保持一致。如果一切都匹配,我将撤回答案。
      • 实际上你是对的,结果 mapred 包不再工作了。设法找到使用 mapreduce 包的较新教程,不知道为什么它不是 Apache 网站上的默认设置。尽管如此,它仍然有效。谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多