Hadoop作业在减少时失败,Java.io.IOException:映射值中的类型不匹配

Hadoop作业在减少时失败,Java.io.IOException:映射值中的类型不匹配,java,hadoop,mapreduce,Java,Hadoop,Mapreduce,我的Map类是 public static class MapClass extends Mapper<LongWritable, Text, Text, LongWritable> { public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { // your map code goes

我的
Map
类是

 public static class MapClass extends Mapper<LongWritable, Text, Text, LongWritable> {

        public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            // your map code goes here
            String[] fields = value.toString().split(",");
            String year = fields[1];
            String claims = fields[8];

            if (claims.length() > 0 && (!claims.startsWith("\""))) {
                context.write(new Text(year), new LongWritable(Long.parseLong(claims)));
            }
        }
    }
数据集看起来像

3070801,1963,1096,,"BE","",,1,,269,6,69,,1,,0,,,,,,,
3070802,1963,1096,,"US","TX",,1,,2,6,63,,0,,,,,,,,, 
当我使用配置运行程序时

        Job job = new Job();
        job.setJarByClass(TopKRecords.class);

        job.setMapperClass(MapClass.class);
        job.setReducerClass(Reduce.class);

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

        job.setJobName("TopKRecords");
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
我认为错误是错误的

java.io.IOException: Type mismatch in value from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1019)
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:691)
    at org.apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80)
    at com.hadoop.programs.TopKRecords$MapClass.map(TopKRecords.java:35)
    at com.hadoop.programs.TopKRecords$MapClass.map(TopKRecords.java:26)
    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:396)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
    at org.apache.hadoop.mapred.Child.main(Child.java:249)
这里怎么了

我看不出有任何不匹配的原因

Mapper<LongWritable, Text, Text, LongWritable>
Reducer<Text, LongWritable, Text, Text>

这显然不对吗

context.write(new Text(year), new LongWritable(Long.parseLong(claims)));
你的地图绘制程序是

Mapper<LongWritable, Text, Text, LongWritable>
Mapper

您已经在此处交换了键和值类型。

在设置过程中还需要以下行:

job.setMapOutputValueClass(LongWritable.class);
从Hadoop 20.2:

这允许用户指定要创建的映射输出值类 与最终输出值类不同

为清晰起见,您还可以添加:

job.setMapOutputKeyClass(Text.class);

但是在这种情况下,这是不必要的。

就键、值映射而言,
Mapper
意味着什么?对不起,如果你是Mapper,那么你做的是正确的,但你的异常只能意味着你交换了它们或至少错误地传递了值部分。我也尝试过,但错误仍然是一样的,我正在调试可能出了什么问题
job.setMapOutputValueClass(LongWritable.class);
job.setMapOutputKeyClass(Text.class);