sdoghds88888 发表于 2018-10-29 13:20:33

Hadoop学习之第四章节:最高温度统计测试程序

import java.io.IOException;  
import org.apache.hadoop.io.IntWritable;
  
import org.apache.hadoop.io.LongWritable;
  
import org.apache.hadoop.io.Text;
  
import org.apache.hadoop.mapreduce.Mapper;
  

  
publicclass MinTemperatureMapper extends Mapper{
  

  
    privatestatic final intMISSING = 9999;
  

  
    @Override
  
    publicvoid map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
  

  
      String line = value.toString();
  
      String year = line.substring(15, 19);
  

  
      int airTemperature;
  
      if(line.charAt(87) == '+') {
  
            airTemperature = Integer.parseInt(line.substring(88, 92));
  
      } else {
  
            airTemperature = Integer.parseInt(line.substring(87, 92));
  
      }
  

  
      String quality = line.substring(92, 93);
  
      if(airTemperature != MISSING && quality.matches("")) {
  
            context.write(new Text(year), new IntWritable(airTemperature));
  
      }
  
    }
  
}


页: [1]
查看完整版本: Hadoop学习之第四章节:最高温度统计测试程序