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

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

 

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

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

 

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

Java代码  Hadoop: LongWritable cannot be cast to org.apache.hadoop.io.IntWritable
  1. public static class TempMapper extends Mapper<LongWritable, Text, IntWritable, FloatWritable>{  
  2.   
  3.   @Override  
  4.   protected void map(<span style="background-color: #ffff00;">LongWritable key</span>, Text value, Context context)  
  5.                 throws IOException, InterruptedException {  
  6.        //code for getting date and temperature  
  7.        String temp = columns.get(3);  
  8.        context.write(new IntWritable(year), new FloatWritable(Float.valueOf(temp)));  
  9.   }  
  10. }  

 

 

坑啊。。

相关文章:

  • 2021-06-02
  • 2021-05-08
  • 2021-09-14
  • 2018-06-22
  • 2021-08-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案