3

有人知道为什么我会收到此错误吗?我看过很多其他类似的帖子,但大多数都不适用于我,我还尝试了一些适用于我的解决方案,但它们没有用,我确定我只是错过了一些愚蠢的东西, 谢谢您的帮助

chris@chrisUHadoop:/usr/local/hadoop-1.0.3/build$ hadoop MaxTemperature 1901 output4
12/07/03 17:23:08 WARN mapred.JobClient: Use GenericOptionsParser for parsing the     arguments. Applications should implement Tool for the same.
12/07/03 17:23:08 INFO input.FileInputFormat: Total input paths to process : 1
12/07/03 17:23:08 INFO util.NativeCodeLoader: Loaded the native-hadoop library
12/07/03 17:23:08 WARN snappy.LoadSnappy: Snappy native library not loaded
12/07/03 17:23:09 INFO mapred.JobClient: Running job: job_201207031642_0005
12/07/03 17:23:10 INFO mapred.JobClient:  map 0% reduce 0%
12/07/03 17:23:28 INFO mapred.JobClient: Task Id : attempt_201207031642_0005_m_000000_0, Status : FAILED
java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1014)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:691)
at org.apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80)
at org.apache.hadoop.mapreduce.Mapper.map(Mapper.java:124)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
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:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
at org.apache.hadoop.mapred.Child.main(Child.java:249)

程序:

import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class MaxTemperatureMapper extends Mapper<LongWritable, Text, Text, IntWritable>{

private static final int MISSING = 9999;

@Override
public void map(LongWritable key, Text value, Context context) 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,92));
    }
    String quality = line.substring(92,93);
    if (airTemperature != MISSING && quality.matches("[01459]"))
    {
        context.write(new Text(year), new IntWritable(airTemperature));
    }
}

}

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class MaxTemperatureReducer extends Reducer<Text, IntWritable, Text, IntWritable>
{
@Override
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException
{
    int maxValue = Integer.MIN_VALUE;
    for (IntWritable value : values)
    {
        maxValue = Math.max(maxValue, value.get());
    }
    context.write(key, new IntWritable(maxValue));
}
}

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class MaxTemperature 
{

public static void main(String[] args) throws Exception 
{
    if (args.length != 2)
    {
        System.out.println("Usage: MaxTemperature <input path> <output path>");
        System.exit(-1);
    }

    Job job = new Job();
    job.setJarByClass(MaxTemperature.class);
    job.setJobName("Max temperature");

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

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

    System.exit(job.waitForCompletion(true) ? 0 : 1);

}
}
4

2 回答 2

2

您似乎缺少许多配置属性:

  • Mapper 和 Reducer 类?- 如果未定义,您将默认使用“身份”映射器/还原器

您的具体错误消息是因为身份映射器只输出它传入的相同键/值类型,在这种情况下可能是 LongWritable 类型的键和 Text 类型的值(因为您尚未定义输入格式,默认为可能是 TextInputFormat)。在您的配置中,您已将输出键类型定义为文本,但映射器正在输出 LongWritable,因此出现错误消息。

于 2012-07-03T23:21:09.940 回答
0

您应该在 job.xml 中设置以下属性

<property>
<name>mapred.input.format.class</name>
<value>org.apache.hadoop.mapred.TextInputFormat</value>
<description>The full class name of the InputFormat class to be used for obtaining the input to the mapper.</description>
</property>
于 2012-07-03T22:24:37.660 回答