MapReduce怎么实现气象站计算最低或最高温度
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,这篇文章主要介绍"MapReduce怎么实现气象站计算最低或最高温度",在日常操作中,相信很多人在MapReduce怎么实现气象站计算最低或最高温度问题上存在疑惑,小编查阅了各式资料,整理出简单好用的
千家信息网最后更新 2025年12月03日MapReduce怎么实现气象站计算最低或最高温度
这篇文章主要介绍"MapReduce怎么实现气象站计算最低或最高温度",在日常操作中,相信很多人在MapReduce怎么实现气象站计算最低或最高温度问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"MapReduce怎么实现气象站计算最低或最高温度"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
TemperatureMR.java
package cn.kissoft.hadoop.week05;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;public class TemperatureMR { public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("Usage: Temperature TemperatureMapper.java
package cn.kissoft.hadoop.week05;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 TemperatureMapper extends Mapper{ 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(0, 4); int airTemperature = Integer.parseInt(line.substring(13, 19).trim()); if (Math.abs(airTemperature) != MISSING) { context.write(new Text(year), new IntWritable(airTemperature)); } }}
MaxTemperatureReducer.java
package cn.kissoft.hadoop.week05;import java.io.IOException;import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Text;import org.apache.hadoop.mapreduce.Reducer;public class TemperatureReducer extends Reducer{ @Override public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { int maxValue = Integer.MIN_VALUE; int minValue = Integer.MAX_VALUE; for (IntWritable value : values) { maxValue = Math.max(maxValue, value.get()); minValue = Math.min(minValue, value.get()); } context.write(key, new IntWritable(maxValue)); context.write(key, new IntWritable(minValue)); }}
运行过程
[wukong@bd11 guide]$ hadoop jar pc.jar cn.kissoft.hadoop.week05.TemperatureMR ./ch02/1959.txt ./ch02/out/Warning: $HADOOP_HOME is deprecated.14/08/15 16:29:32 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.14/08/15 16:29:32 INFO input.FileInputFormat: Total input paths to process : 114/08/15 16:29:32 INFO util.NativeCodeLoader: Loaded the native-hadoop library14/08/15 16:29:32 WARN snappy.LoadSnappy: Snappy native library not loaded14/08/15 16:29:34 INFO mapred.JobClient: Running job: job_201408151617_000314/08/15 16:29:35 INFO mapred.JobClient: map 0% reduce 0/08/15 16:29:47 INFO mapred.JobClient: map 100% reduce 0/08/15 16:30:00 INFO mapred.JobClient: map 100% reduce 100/08/15 16:30:04 INFO mapred.JobClient: Job complete: job_201408151617_000314/08/15 16:30:04 INFO mapred.JobClient: Counters: 2914/08/15 16:30:04 INFO mapred.JobClient: Job Counters 14/08/15 16:30:04 INFO mapred.JobClient: Launched reduce tasks=114/08/15 16:30:04 INFO mapred.JobClient: SLOTS_MILLIS_MAPS=1498914/08/15 16:30:04 INFO mapred.JobClient: Total time spent by all reduces waiting after reserving slots (ms)=014/08/15 16:30:04 INFO mapred.JobClient: Total time spent by all maps waiting after reserving slots (ms)=014/08/15 16:30:04 INFO mapred.JobClient: Launched map tasks=114/08/15 16:30:04 INFO mapred.JobClient: Data-local map tasks=114/08/15 16:30:04 INFO mapred.JobClient: SLOTS_MILLIS_REDUCES=1282514/08/15 16:30:04 INFO mapred.JobClient: File Output Format Counters 14/08/15 16:30:04 INFO mapred.JobClient: Bytes Written=1914/08/15 16:30:04 INFO mapred.JobClient: FileSystemCounters14/08/15 16:30:04 INFO mapred.JobClient: FILE_BYTES_READ=918048614/08/15 16:30:04 INFO mapred.JobClient: HDFS_BYTES_READ=2754447514/08/15 16:30:04 INFO mapred.JobClient: FILE_BYTES_WRITTEN=1388690814/08/15 16:30:04 INFO mapred.JobClient: HDFS_BYTES_WRITTEN=1914/08/15 16:30:04 INFO mapred.JobClient: File Input Format Counters 14/08/15 16:30:04 INFO mapred.JobClient: Bytes Read=2754436814/08/15 16:30:04 INFO mapred.JobClient: Map-Reduce Framework14/08/15 16:30:04 INFO mapred.JobClient: Map output materialized bytes=459024014/08/15 16:30:04 INFO mapred.JobClient: Map input records=44426414/08/15 16:30:04 INFO mapred.JobClient: Reduce shuffle bytes=459024014/08/15 16:30:04 INFO mapred.JobClient: Spilled Records=125188214/08/15 16:30:04 INFO mapred.JobClient: Map output bytes=375564614/08/15 16:30:04 INFO mapred.JobClient: Total committed heap usage (bytes)=21886566414/08/15 16:30:04 INFO mapred.JobClient: CPU time spent (ms)=628014/08/15 16:30:04 INFO mapred.JobClient: Combine input records=014/08/15 16:30:04 INFO mapred.JobClient: SPLIT_RAW_BYTES=10714/08/15 16:30:04 INFO mapred.JobClient: Reduce input records=41729414/08/15 16:30:04 INFO mapred.JobClient: Reduce input groups=114/08/15 16:30:04 INFO mapred.JobClient: Combine output records=014/08/15 16:30:04 INFO mapred.JobClient: Physical memory (bytes) snapshot=32298598414/08/15 16:30:04 INFO mapred.JobClient: Reduce output records=214/08/15 16:30:04 INFO mapred.JobClient: Virtual memory (bytes) snapshot=145557913614/08/15 16:30:04 INFO mapred.JobClient: Map output records=417294
运行结果
[wukong@bd11 guide]$ hadoop fs -cat ./ch02/out/part-r-00000
Warning: $HADOOP_HOME is deprecated.1959 4181959 -400
截图

到此,关于"MapReduce怎么实现气象站计算最低或最高温度"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
最低
最高
气象
气象站
温度
学习
更多
帮助
运行
实用
接下来
截图
文章
方法
理论
知识
篇文章
结果
网站
资料
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全之web渗透测试
科信大队网络安全检查简报
保定C 软件开发
江苏省机关网络安全竞赛
关于网络安全的感受50字
电脑直接连接网关服务器
常熟推广网络技术要多少钱
机房服务器访问管理系统
钉钉部门数据库设计
宁波畅联软件开发有限公司
6g技术是网络技术吗
软件开发销售财务
网络安全保险市场情况
信息网络安全模拟考试
ftp服务器评测
新能源网络技术收购价
广州趣野营网络技术有限公司
无线网络技术有什么功能
游戏服务器安装安全软件下载
c编写服务器
广州天祥互联网科技有限公司
海南安迈云网络技术公司
wins 服务器设置
网站域名服务器如何配置
pmp软件开发管理
汕头 戴尔维修服务器
图片缓存服务器配置
王者重新登录找不到服务器怎么办
数据库 逻辑删除
阿卡索资讯软件开发