hadoop自己写的最高温度程序源码
package com.teset;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class Tempreature extends Configured implements Tool {
// 输入的是行偏移量,一行文本,输出的是 一个年份 最高温度
public static class TemMapper extends
Mapper<LongWritable, Text, Text, IntWritable> {
@Override
protected void map(LongWritable key, Text value,
Mapper<LongWritable, Text, Text, IntWritable>.Context context)
throws IOException, InterruptedException {
// map处理数据
String str = value.toString();
String year = null;
int Maxtemp = 0;
StringTokenizer tokenstr = new StringTokenizer(str);
int i=0;
while (tokenstr.hasMoreTokens()) {
String tempstr = tokenstr.nextToken();
i++;
if (i==1){
year =tempstr;
continue;
}else if (i==5&&Integer.parseInt(tempstr)!=-9999){
int tepMax = Integer.parseInt(tempstr);
Maxtemp =Math.max(tepMax, Maxtemp);
context.write(new Text(year), new IntWritable(Maxtemp));
break;
}
}
}
}
public static class TempReducer extends
Reducer<Text, IntWritable, Text, IntWritable> {
@Override
protected void reduce(Text key, Iterable<IntWritable> values,
Reducer<Text, IntWritable, Text, IntWritable>.Context context)
throws IOException, InterruptedException {
int Maxtem = Integer.MIN_VALUE;
for (IntWritable value:values){
Maxtem = Math.max(Maxtem, value.get());
}
context.write(key, new IntWritable(Maxtem));
}
}
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new Tempreature(), args);
System.exit(res);
}
@Override
public int run(String[] arg0) throws Exception {
Configuration conf = getConf();
Job job = new Job(conf,"MaxTem");//任务名
job.setJarByClass(Tempreature.class);//指定class
//输入和输出流
FileInputFormat.addInputPath(job, new Path(arg0[0]));
FileOutputFormat.setOutputPath(job, new Path(arg0[1]));
job.setMapperClass(TemMapper.class);//map
job.setReducerClass(TempReducer.class);
job.setCombinerClass(TempReducer.class);
job.setOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.waitForCompletion(true);
return job.isSuccessful()?0:1;
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
hadoop自己写的最高温度程序源码的更多相关文章
- MongoDB源码分析——mongod程序源码入口分析
Edit 说明:第一次写笔记,之前都是看别人写的,觉得很简单,开始写了之后才发现真的很难,不知道该怎么分析,这篇文章也参考了很多前辈对MongoDB源码的分析,也有一些自己的理解,后续将会继续分析其他 ...
- 反编译获取线上任何微信小程序源码(转)
看到人家上线的小程序的效果,纯靠推测,部分效果在绞尽脑汁后能做出大致的实现,但是有些细节,费劲全力都没能做出来.很想一窥源码?查看究竟?看看大厂的前端大神们是如何规避了小程序的各种奇葩的坑?那么赶紧来 ...
- 【最新】破解微信小程序,获取微信小程序源码,破解微信wxapkg,仅需5秒
一个后端第一次接触iview,就简单写了个网站. 之前看到有人发解析wx小程序源码包的软件,但是因为微信的升级,之前的办法已经不行了.现在重新改了js文件,适配了最新的版本. 之前微信wxapkg包获 ...
- 【转】反编译获取任何微信小程序源码(完)
一.前言最近在学习微信小程序开发,半个月学习下来,很想实战一下踩踩坑,于是就仿写了一个阿里妈妈淘宝客小程序的前端实现,过程一言难尽,差不多两周时间过去了,发现小程序的坑远比想象的要多的多!!在实际练手 ...
- OpenCV开发笔记(五十六):红胖子8分钟带你深入了解多种图形拟合逼近轮廓(图文并茂+浅显易懂+程序源码)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- OpenCV开发笔记(六十五):红胖子8分钟带你深入了解ORB特征点(图文并茂+浅显易懂+程序源码)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- 如何实现微信小程序动画?添加到我的小程序动画实现详细讲解,轻松学会动画开发!附壁纸小程序源码下载链接
为了让用户能尽可能多地使用小程序,也算是沉淀用户,现在很多小程序中,都有引导用户"添加到我的小程序"的操作提示,而且大多都是有动画效果.在高清壁纸推荐小程序首页,用户每次进入,都会 ...
- C#实现联通短信Sgip协议程序源码
此程序为中国联通Sgip协议程序接口,适合在中国联通申请了短信发送端口的公司使用. 短信群发已经成为现在软件系统.网络营销等必不可少的应用工具.可应用在短信验证.信息群发.游戏虚拟商品购买.事件提醒. ...
- 复用微信小程序源码包后仍然有原小程序的版本管理怎么处理
前言: 复用微信小程序源码包后,重新创建项目导入源码包,会发现开发者工具版本管理中仍然有原来小程序的版本,这样就不太好了.毕竟是一个新的小程序,需要有新的版本控制的.那么这个问题怎么处理呢? 解决方案 ...
随机推荐
- C#练习DataReader
SQL代码: create database ThreeDb go USE ThreeDb; GO CREATE TABLE classify --分类表 ( id ,), name ) not nu ...
- shell按行合并文件
file1abc file2123 如何合并两个文件,得到a 1b 2c 3 awk方式 awk 'NR==FNR{a[NR]=$0}NR>FNR{print a[FNR],$0}' file1 ...
- UVALive - 7427 the math 【二分匹配】
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- Swift URL encode
前言 在WEB前端开发,服务器后台开发,或者是客户端开发中,对URL进行编码是一件很常见的事情,但是由于各个年代的RFC文档中的内容一直在变化,一些年代久远的代码就对URL编码和解码的规则和现在的有一 ...
- 【leetcode】Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- 【leetcode刷题笔记】Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- vmstat测试
vmstat测试:场景:tar -zvcf 2_104.tar.gz ./* 打包压缩3GB+文件 [root@localhost opt]# vmstat 1 1000procs --------- ...
- Codeforces 337D Book of Evil:树的直径【结论】
题目链接:http://codeforces.com/problemset/problem/337/D 题意: 给你一棵树,n个节点. 如果一个节点处放着“罪恶之书”,那么它会影响周围距离不超过d的所 ...
- JSP分页1
分页 1.什么分页? 第N页/共M页 首页 上一页 1 2 3 4 5 6 7 8 9 10 下一页 尾页 口 go 分页的优点:只查询一页,不用查询所有页! 2.分页数据 页面的数据都是由Servl ...
- 【BZOJ 4709】柠檬 斜率优化dp+单调栈
题意 给$n$个贝壳,可以将贝壳分成若干段,每段选取一个贝壳$s_i$,这一段$s_i$的数目为$num$,可以得到$num^2\times s_i$个柠檬,求最多能得到几个柠檬 可以发现只有在一段中 ...