标签:hadoop
package com.javaMapReduce; 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.mapred.JobConf; import org.apache.hadoop.mapred.Mapper; import org.apache.hadoop.mapred.OutputCollector; import org.apache.hadoop.mapred.Reporter; import org.apache.hadoop.mapreduce.Mapper.Context; public class MaxTemperatureMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { private static final int MISSING = 9999; @Override public void configure(JobConf arg0) { // TODO Auto-generated method stub } @Override public void close() throws IOException { // TODO Auto-generated method stub } @Override public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> arg2, Reporter arg3) throws IOException { } @Override public void map(LongWritable key,Text value,Context context) throws IOException,InterruptedException { // TODO Auto-generated method stub 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)); } } }
标签:hadoop
原文地址:http://songchenguang.blog.51cto.com/5366243/1782720