Hadoop: LongWritable cannot be cast to org.apache.hadoop.io.IntWritable

2023-06-13,,

写MR Job的时候遇到一个坑爹的异常:

LongWritable cannot be cast to org.apache.hadoop.io.IntWritable

当写Map的时候,key的默认输入就是LongWritable。

因为LongWritable指代Block中的数据偏移量。

所以把它强行转换成Text当然就Error了。。

    public static class TempMapper extends Mapper<LongWritable, Text, IntWritable, FloatWritable>{
    @Override
    protected void map(<span style="background-color: #ffff00;">LongWritable key</span>, Text value, Context context)
    throws IOException, InterruptedException {
    //code for getting date and temperature
    String temp = columns.get(3);
    context.write(new IntWritable(year), new FloatWritable(Float.valueOf(temp)));
    }
    }

坑啊。。

Hadoop: LongWritable cannot be cast to org.apache.hadoop.io.IntWritable的相关教程结束。

《Hadoop: LongWritable cannot be cast to org.apache.hadoop.io.IntWritable.doc》

下载本文的Word格式文档,以方便收藏与打印。