mapreduce求每年的最低温度
来源:互联网 发布:淘宝商城 天猫渔具 编辑:程序博客网 时间:2024/04/30 17:46
main
import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Textimport org.apache.hadoop.mapreduce.Jobimport org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutFormatpublic class MinTemperature{public static void main(String [] args){if(args.length!=2){System.out.println("Usage:MinTemperature<input path><output path>");System.exit(-1);}Job job = new Job(); job.setJarByClass(MinTemperature.class); job.setJobName("Min temperature"); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); job.setMapperClass(MinTemperatureMapper.class); job.setReducerClass(MinTemperatureReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); System.exit(job.waitForCompletion(true) ? 0 : 1); }}
mapper
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 MinTemperatureMapper extends Mapper<LongWritable,Text,Text,IntWritable>{private static final int MISSING=9999;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.match("[01459]")){context.write(new Text(year),new IntWritable(airTemperature));}}}
reducer
import java.io.IOException;import org.apache.hadoop.io.IntWritable;import org.apahce.hadoop.io.Text;import org.apache.hadoop.mapreduce.Reducer;public class MinTemperaureReducer extends Reducer <Text,IntWriable,Text,IntWriable>{public void reduce(Text key,Iterable<IntWriable> values,Context context)throws IOException,InterruptedException{int minValue =Integer.MAX_VALUE;for(IntWriable value:values){minValue =Math.min(minValue,value.get());}context.write(key,new IntWriable(minValue));}}
0 0
- mapreduce求每年的最低温度
- hadoop实验:求气象数据的最低温度
- 案例一:基于MapReduce求每年的最大天气
- 求每年最高气温
- 简单的MapReduce例子,从一批数据中获取每年的最高温度
- 每年的码农都流去哪了?
- 每年的码农都流去哪了?
- 每年WWDC的记录
- 每年的节假日数据处理
- Hadoop-02-第一个MapReduce程序--统计每年最高温度
- 写在每年开学的日子
- 【转】每年的码农都流去哪了?
- 每年WWDC的英文记录
- 求出每年每月的日历
- 统计每年每月的信息
- Mapreduce求TopK最大值
- mapReduce求最大值
- MapReduce求最大值
- 二叉树的非递归遍历
- regsvr32.exe使用
- Implement strStr()
- Android Dialog用法
- 反其道而行之1
- mapreduce求每年的最低温度
- STL学习小结
- JAVA内部类使用,什么时候该使用内部类及使用内部类的好处
- 黑马程序员————Java基础之入门系列001
- 如何解决Maven jar包依赖版本冲突(dependency collision)
- rootfs 启动出错
- Activity跳转黑屏,闪屏,白屏解决
- Android第22天 BroadCast
- linux下cocos2dx安装过程分享