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

前端 未结 1 1072
再見小時候
再見小時候 2021-01-12 23:03

I want to take a mean value of a temperature given in an input file and my Mapper and Reducer synatax seems fine to me but I am still getting the following error:

         


        
相关标签:
1条回答
  • 2021-01-12 23:33

    The key class of a mapper that maps text files is always LongWritable. That is because it contains the byte offset of the current line and this could easily overflow an integer.

    Basically you need to change your code to this:

    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)));
      }
    }
    
    0 讨论(0)
提交回复
热议问题