9

MapReduceプログラムを作成しました。コードは次のとおりです。

import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class MaxTemperature {

public class MaxTemperatureMapper extends Mapper <LongWritable, Text, Text, IntWritable>{
    private static final int MISSING = 9999;

    public void map(LongWritable key, Text Value, Context context, Reporter reporter) throws IOException, InterruptedException{
        String line = Value.toString();
        String year = line.substring(15,19);
        int airTemperature;
        if(line.charAt(87)=='+')
            airTemperature = Integer.parseInt(line.substring(88,92));
        else
            airTemperature = Integer.parseInt(line.substring(87,91));
        String quality = line.substring(92,93);
        if(airTemperature!=MISSING && quality.matches("[01459]"))
            context.write(new Text(year), new IntWritable(airTemperature));
    }
}

public class MaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable>{
    public void reduce (Text Key, Iterator<IntWritable> Values, Context context, Reporter reporter) throws IOException, InterruptedException{

        int maxValue = Integer.MIN_VALUE;
        while(Values.hasNext())
            maxValue = Math.max(maxValue, Values.next().get());
        context.write(Key, new IntWritable(maxValue));

    }
}

public static void main(String[] args) throws Exception {
    if(args.length!=2){
        System.err.println("Usage: WeatherTemperature  <input path> <output path>");
        System.exit(-1);
    }
    Configuration conf = new Configuration();
    Job job = new Job(conf, "Maximum Temperature Calculator");
    job.setJarByClass(MaxTemperature.class);

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

    job.setMapperClass(MaxTemperatureMapper.class);
    job.setReducerClass(MaxTemperatureReducer.class);

//  job.setInputFormatClass(TextInputFormat.class);
    //job.setOutputFormatClass(TextOutputFormat.class);
    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));
    job.waitForCompletion(true);
    }
}

次のコマンドを使用して、このプログラムの.jarを実行します。

hadoop jar weather.jar MaxTemperature input output

そして、次のエラーが発生します。

12/06/13 00:52:05 INFO mapred.JobClient: Task Id :     attempt_201206121354_0007_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.NoSuchMethodException:      MaxTemperature$MaxTemperatureMapper.<init>()
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:602)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:323)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:270)
    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:1177)
    at org.apache.hadoop.mapred.Child.main(Child.java:264)
Caused by: java.lang.NoSuchMethodException: MaxTemperature$MaxTemperatureMapper.<init>()
    at java.lang.Class.getConstructor0(Class.java:2706)
    at java.lang.Class.getDeclaredConstructor(Class.java:1985)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:109)
    ... 7 more

このエラーはどういう意味ですか?そして、私は何を間違っているのですか、どうすればそれを修正できますか?ありがとう!

4

3 に答える 3

37

マッパークラスとレデューサークラスは静的に定義する必要があります。そうしないと、コンパイルによって単一の引数(親MaxTemperatureクラス)を持つコンストラクターが作成されます。したがって、デフォルトのコンストラクターはありません。

public static class MaxTemperatureMapper extends Mapper<....

public static class MaxTemperatureReducer extends Reducer<....
于 2012-06-13T20:39:48.667 に答える
1

Mapperデフォルトのコンストラクターがないのではないかと思いますが、コンストラクターはこれだけですMaxTemperatureMapper

于 2012-06-13T20:32:42.490 に答える
1

scalaカスタムのデフォルトコンストラクターで同様のエラーを修正KEYMapperましたReducer

問題

15/05/12 01:07:57 WARN mapred.LocalJobRunner: job_local1713686765_0001
java.lang.Exception: java.io.IOException: Initialization of all the collectors failed. Error in last collector was :java.lang.NoSuchMethodException: IntPair.<init>()
    at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
Caused by: java.io.IOException: Initialization of all the collectors failed. Error in last collector was :java.lang.NoSuchMethodException: IntPair.<init>()
    at org.apache.hadoop.mapred.MapTask.createSortingCollector(MapTask.java:414)
    at org.apache.hadoop.mapred.MapTask.access$100(MapTask.java:81)
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.<init>(MapTask.java:698)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:770)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
    at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:243)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

解決策-デフォルトのコンストラクター

class IntPair (first : IntWritable, second : IntWritable) extends WritableComparable[IntPair] {

      def this() = this(first = new IntWritable(), second = new IntWritable())

     def getFirst () : IntWritable = {
         first
     }

     def getSecond () : IntWritable = {
         second
     }

}
于 2015-05-12T06:40:06.057 に答える