3

解決策:より良いチュートリアルを使用してください-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プログラムは、ApacheMapReduceチュートリアルのプログラムです。MountainLionでHadoop1.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);

}
}
4

2 に答える 2

9

問題はAPIの選択ではありません。安定した(mapred。*)APIと進化する(mapreduce。*)APIの両方が完全にサポートされており、フレームワーク自体が両方のテストを実行して、リリース間でリグレッションや破損がないことを確認します。

問題はこの行です:

conf.setReducerClass(Reducer.class);

代わりにReducerインターフェースの実装を設定する必要がある場合は、ReducerインターフェースをReducerとして設定します。次のように変更します。

conf.setReducerClass(Reduce.class);

修正します。

于 2012-09-10T11:34:09.720 に答える
1

hadoop.mapredパッケージの代わりにhadoop.mapreduceパッケージを使用していることを確認してください。mapredパッケージは古く、現在のバージョンのmapreduceクラスとは異なるメソッドがクラスにあります。

于 2012-08-14T22:20:47.187 に答える