hadoop实验:求气象数据的最低温度
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实验:求气象数据的最低温度的更多相关文章
- Hadoop—MapReduce计算气象温度
Hadoop-MapReduce计算气象温度 1 运行环境说明 1.1 硬软件环境 主机操作系统:Mac OS 64 bit ,8G内存 虚拟软件:Parallers Desktop12 虚拟机操作系 ...
- 基于python的《Hadoop权威指南》一书中气象数据下载和map reduce化数据处理及其可视化
文档内容: 1:下载<hadoop权威指南>中的气象数据 2:对下载的气象数据归档整理并读取数据 3:对气象数据进行map reduce进行处理 关键词:<Hadoop权威指南> ...
- Hadoop MapReduce编程 API入门系列之挖掘气象数据版本3(九)
不多说,直接上干货! 下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 下面是版本2. Hadoop MapReduce编程 API入门系列之挖掘气象数 ...
- Hadoop MapReduce编程 API入门系列之挖掘气象数据版本2(十)
下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 这篇博文,包括了,实际生产开发非常重要的,单元测试和调试代码.这里不多赘述,直接送上代码. MRUni ...
- 全国气象数据/降雨量分布数据/太阳辐射数据/NPP净初级生产力数据/植被覆盖度数据
气象数据一直是一个价值较高的数据,它被广泛用于各个领域的研究当中.气象数据包括有气温.气压.相对湿度.降水.蒸发.风向风速.日照等多种指标,但是包含了这些全部指标的气象数据却较难获取 ...
- python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发接口
!/usr/bin/python #encoding=utf-8 #Author:Ruiy #//////////////////////////////////////////////////// ...
- java处理中国气象数据,提取汇总陕西地区24小时各观测点的数据(csv格式)
1.先贴一下气象数据的csv源格式,由于数据内容较多,就放一部分(china_sites_20150102.csv) date,hour,type,1001A,1002A,1003A,1004A,10 ...
- 附录C 准备NCDC气象数据(加解释)
附录C 准备NCDC气象数据 这里首先简要介绍如何准备原始气象数据文件,以便我们能用Hadoop对它们进行分析.如果打算得到一份数据副本供Hadoop处理,可按照本书配套网站(网址为http://ww ...
- 广西省行政村边界shp数据/广西省乡镇边界/广西省土地利用分类数据/广西省气象数据/降雨量分布数据/太阳辐射数据
数据下载链接:数据下载链接 广西壮族自治区,地处中国南部,北回归线横贯中部,属亚热带季风气候区.南北以贺州--东兰一线为界,此界以北属中亚热带季风气候区,以南属南亚热带季风气候区. 数据范围:全 ...
随机推荐
- ASP.NET Application and Page Life Cycle
ASP.NET Application Life Cycle Overview for IIS 7.0 https://msdn.microsoft.com/en-us/library/bb47025 ...
- php中file_get_contents如何读取大容量文件
php中file_get_contents如何读取大容量文件 一.总结 一句话总结:使用file_get_contents()进行分段读取,file_get_contents()函数可以分段读取 1. ...
- zzulioj--1827--石锅全拌(区间求和水题)
1827: 石锅全拌 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 6 Solved: 3 SubmitStatusWeb Board Descri ...
- 14.hash_set(已过时,被unorded_set替代)
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS #include <iostream> #include <hash_set> ...
- <Sicily>Pair
一.题目描述 The N cities of Estiah are connected by N-1 roads. The roads are built in a way that it's alw ...
- tab.py
vim tab.py #!/usr/bin/env python # #Tab import sys import readline import rlcompleter import atexit ...
- spring data jpa实体类映射配置
@Entity:用来标志实体类,知名这是一个和数据库表映射的实体类 @Id注解指明这个属性映射为数据库的主键 @GeneratedValue注解默认使用主键生成方式为自增,hibernate会自动生成 ...
- 题解 CF383C 【Propagating tree】
这道题明明没有省选难度啊,为什么就成紫题了QAQ 另:在CF上A了但是洛谷Remote Judge玄学爆零. 思路是DFS序+线段树. 首先这道题直观上可以对于每一次修改用DFS暴力O(n),然后对于 ...
- [Poi] Use Markdown as React Components by Adding a Webpack Loader to Poi
Poi ships with many webpack loaders included, but you may run into scenarios where you'll need to cu ...
- [Python] ndArray of numpy
NumPy Reference: Mathematical functions numpy.sum: Sum of elements - along rows, columns or all nump ...