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. springMVC之拦截器

    有两种方法配置spring的拦截器 1. 实现接口: HandleInterceptor public class MyInterceptor1 implements HandlerIntercept ...

  2. Unity 内置Shader变量、辅助函数等

    一:标准库里的常用.cginc文件 HLSLSupport.cginc - (automatically included) Helper macros and definitions for cro ...

  3. angularjs 模块化

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  4. 解决Linux下yum安装无法解析URL的问题

    问题: [root@yaya ~]# yum -y install gcc-* Loaded plugins: fastestmirror, presto Could not retrieve mir ...

  5. 安卓开发--WebView

    package com.zhangxi.test01; import android.app.Activity;import android.app.ProgressDialog;import and ...

  6. jqueryValidator自定义校验规则的一种方式(覆盖源码)

    1.自定义js文件:jqValid-extend.js 内容: function setDefaultValidate(){ $.extend(true, $.validator, { // 方法 m ...

  7. .net Web获取域用户账号

    HttpContext.Current.Request.LogonUserIdentity.Name //可以获取出域账号 HttpContext.Current.Request.LogonUserI ...

  8. Host status showing red icon in chronograph, Chronograf主机列表页显示主机状态为红色标志

    刚开始全部装好的时候主机显示的状态是绿色的,过了些日子我再打开看的时候就变成红色的了,点击主机进去查看的时候没有了图表数据,大概是这样子的, 在influxdb数据库主机上执行命令curl " ...

  9. Ubuntu(kali)开启mysql远程连接

    Linux 默认关闭mysql的远程连接,编辑 /etc/mysql/my.cnf 文件, 把里面的 bind-address = 127.0.0.1 改成 bind-address = 0.0.0. ...

  10. url链接打开本地应用(测试通过)

    基于windows!! 类比mailto://XXXX 主要参考: https://www.cnblogs.com/snow365/p/6428212.html 应用 1.在网页上本地办公 网页应用越 ...