lihanchuan125 发表于 2016-12-10 09:32:39

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

  写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)));
}
}
  坑啊。。
页: [1]
查看完整版本: Hadoop: LongWritable cannot be cast to org.apache.hadoop.io.IntWritable