1.下载部分数据。由于实验就仅仅下载2003年的部分气象数据

2.通过zcat *gz > sample.txt命令解压重定向

[hadoop@Master test_data]$ zcat *gz > /home/hadoop/input/sample.txt

3.查看数据格式

4.把文件sample.txt放进hdfs文件系统里

[hadoop@Master input]$ hadoop fs -put /home/hadoop/input/sample.txt  /user/hadoop/in/sample.txt

5.Maper : MinTemperatureMapper.java

 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; @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;
airTemperature= Integer.parseInt(line.substring(14, 19).trim()); if (airTemperature!= MISSING) {
context.write(new Text(year), new IntWritable(airTemperature));
}
}

6.Reducer :MinTemperatureReducer.java

import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer; public class MinTemperatureReducer
extends Reducer<Text, IntWritable, Text, IntWritable>
{ @Override
public void reduce(Text key, Iterable<IntWritable> values,Context context)
throws IOException, InterruptedException
{ int minValue= Integer.MAX_VALUE;
for (IntWritable value : values)
{
minValue= Math.min(minValue, value.get());
}
context.write(key, new IntWritable(minValue));
}
}

7.M-R Job :MinTemperature.java

import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; public class MinTemperature
{
public static void main(String[] args) throws Exception
{
if (args.length!= 2)
{
System.err.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);
}
}

8.编译,压缩成jar 包

[hadoop@Master myclass]$ javac -classpath /usr/hadoop/hadoop-core-1.2.1.jar  MinTemperature*.java

[hadoop@Master myclass]$ jar cvf MinTemperature.jar MinTemperature*.class

added manifest

adding: MinTemperature.class(in = 1417) (out= 799)(deflated 43%)

adding: MinTemperatureMapper.class(in = 1740) (out= 722)(deflated 58%)

adding: MinTemperatureReducer.class(in = 1664) (out= 707)(deflated 57%)

9.运行作业

[hadoop@Master myclass]$ hadoop jar /usr/hadoop/myclass/MinTemperature.jar MinTemperature  /user/hadoop/in/sample.txt  ./out2

运行报错。发现报错,信息例如以下

找了半天原因。发现是没删掉class ,程序找不到类。在myclass 文件下删掉class文件。仅仅保留生成的jar包

[hadoop@Master myclass]$ rm MinTemperature*.class

10.查看结果



hadoop实验:求气象数据的最低温度的更多相关文章

  1. Hadoop—MapReduce计算气象温度

    Hadoop-MapReduce计算气象温度 1 运行环境说明 1.1 硬软件环境 主机操作系统:Mac OS 64 bit ,8G内存 虚拟软件:Parallers Desktop12 虚拟机操作系 ...

  2. 基于python的《Hadoop权威指南》一书中气象数据下载和map reduce化数据处理及其可视化

    文档内容: 1:下载<hadoop权威指南>中的气象数据 2:对下载的气象数据归档整理并读取数据 3:对气象数据进行map reduce进行处理 关键词:<Hadoop权威指南> ...

  3. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本3(九)

    不多说,直接上干货! 下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 下面是版本2. Hadoop MapReduce编程 API入门系列之挖掘气象数 ...

  4. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本2(十)

    下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 这篇博文,包括了,实际生产开发非常重要的,单元测试和调试代码.这里不多赘述,直接送上代码. MRUni ...

  5. 全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据

    ​        气象数据一直是一个价值较高的数据,它被广泛用于各个领域的研究当中.气象数据包括有气温.气压.相对湿度.降水.蒸发.风向风速.日照等多种指标,但是包含了这些全部指标的气象数据却较难获取 ...

  6. python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发接口

    !/usr/bin/python #encoding=utf-8 #Author:Ruiy #//////////////////////////////////////////////////// ...

  7. java处理中国气象数据,提取汇总陕西地区24小时各观测点的数据(csv格式)

    1.先贴一下气象数据的csv源格式,由于数据内容较多,就放一部分(china_sites_20150102.csv) date,hour,type,1001A,1002A,1003A,1004A,10 ...

  8. 附录C 准备NCDC气象数据(加解释)

    附录C 准备NCDC气象数据 这里首先简要介绍如何准备原始气象数据文件,以便我们能用Hadoop对它们进行分析.如果打算得到一份数据副本供Hadoop处理,可按照本书配套网站(网址为http://ww ...

  9. 广西省行政村边界shp数据/广西省乡镇边界/广西省土地利用分类数据/广西省气象数据/降雨量分布数据/太阳辐射数据

    ​  数据下载链接:数据下载链接 广西壮族自治区,地处中国南部,北回归线横贯中部,属亚热带季风气候区.南北以贺州--东兰一线为界,此界以北属中亚热带季风气候区,以南属南亚热带季风气候区. 数据范围:全 ...

随机推荐

  1. How to: Create Custom Configuration Sections Using ConfigurationSection

    https://msdn.microsoft.com/en-us/library/2tw134k3.aspx You can extend ASP.NET configuration settings ...

  2. hdoj--2709--Sumsets(数位dp)

    Sumsets Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  3. hdoj--3183--A Magic Lamp(贪心)

    A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  4. 那些不兼容 IE11的网站(持续更新)

    此博文用于收集不兼容 IE11 的网站,持续更新,请网站开发者自己认领: 兼容性引起的功能缺陷: v.qq.com (提示未安装 Flash 播放器,这问题我反馈几百年了,还没修复) tv.sohu. ...

  5. PostgreSQL Replication之第七章 理解Linux高可用(1)

    高可用(HA)是工业长期持续的,不间断的服务.在本章,您将了解高可用软件的历史,概念和实现与PostgreSQL复制和高可用之间的关系. 本章将详细地讲述如下主题: •理解高可用性的目的 •衡量可用性 ...

  6. python 基础使用list、dict、set、可变与不可变对象

    参考链接:https://www.liaoxuefeng.com/wiki/1016959663602400/1017104324028448 dict是字典,可以储存键值对类型的值,set与dict ...

  7. Python组织文件 实践:拷贝某种类型的所有文件

    #! python3 #chapter09-test01- 遍历目录树,查找特定扩展名的文件不论这些文件的位置在哪里,都将他们 #拷贝到一个新的文件夹中 import os,shutil,pprint ...

  8. 如何使用Java创建Excel(.xls 和 .xlsx)文件 并写入数据

    1,需要依赖的jar包, <!-- POI(operate excel) start --> <!-- the version of the following POI packag ...

  9. Python学习笔记(2)--基本数据类型

    在介绍基本数据类型之前,先说一个系统方法type():返回对象的数据类型,可以帮助我们查看系统的类型定义 python不同的版本,类型名称稍有不同,这里使用的是3.5.2版本 一.基本数据类型: 1. ...

  10. ZJU 1346 Comparing Your Heroes 状态压缩DP 拓扑排序的计数

    做多校的时候遇见一个求拓扑排序数量的题,就顺便来写了一下. 题意: 你有个朋友是KOF的狂热粉丝,他有一个对其中英雄的强弱比较,让你根据这些比较关系来给这些英雄排名.问一共有多少种排名方式. 思路: ...