写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(LongWritable key, 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类型转换为IntWritable类型的错误。通过分析代码,发现直接转换会导致错误。文章详细解释了原因并提供了解决方案。
3991

被折叠的 条评论
为什么被折叠?



