码迷,mamicode.com
首页 > 移动开发 > 详细

mapreduce-查找最高气温的Mapper类

时间:2015-01-31 20:39:01      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

package com;


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;


public class MaxTemperatureMapper extends Mapper<LongWritable, Text, Text, IntWritable> {


private static final int MISSING = 9999;

@Override 
public void 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("[01459]")){
context.write(new Text(year), new IntWritable(airTemperature));
}
}
}

mapreduce-查找最高气温的Mapper类

标签:

原文地址:http://blog.csdn.net/u012965373/article/details/43344415

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!