Application to find the maximum temperature in the weather dataset
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 MaxTemperature {
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: MaxTemperature <input path> <output path>");
System.exit(-1);
} Job job = new Job();
job.setJarByClass(MaxTemperature.class);
job.setJobName("Max temperature");
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1])); job.setMapperClass(MaxTemperatureMapper.class);
job.setReducerClass(MaxTemperatureReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class); System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
Job对象指定了作业的各种参数.它授予你对整个作业如何运行的控制权.当我 们在 Hadoop 集群上运行这个作业时,我们把代码打包成一个 JAR 文件(Hadoop 会在集群分发这个包).我们没有明确指定 JAR 文件的名称,而是在 Job构造函数中传送一个类,Hadoop 会找到这个包含此类的 JAR 文件.
在创建 Job对象后,我们将指定输入和输出的路径.通过调用 FileInputFormat 内的静态方法 addInputPath()来定义输入的路径,它可以是单个 文件,目录(本例中,输入的内容组成此目录下所有文件)或文件模式的路径.同时, addInputPath()可被调用多次从而实现使用多路径输入.
输出路径(其中只有一个)是在 FileOutputFormat 内的静态方法 setOutputPath()来指定的.它指定了 reduce 函数输出文件写入的目录.在运行作业前该目录不应该存在,否则 Hadoop 会报错并且拒绝运行任务.这种预防措施是为了防止 数据丢失(一个长时间的任务可能非常恼人地被另一个意外覆盖).
接下来,通过 setMapperClass()和 setReducerClass()这两个方法来指定要使 用的 map 和 reduce 类型. setOutputKeyClass()和 setOutputValueClass()方法控制 map 和 reduce 函数的输出类型,正如本例所示,这两个方法往往是相同的.如果它们不同,那么 map 的输出类型可设置成使用 setMapOutputKeyClass()和 setMapOutputValueClass()方法.
输入的类型通过输入格式来控制,我们没有设置,因为我们使用的是默认的 TextInputFormat(文本输入格式).
在设置了定义 map 和 reduce 函数的类之后,运行作业的准备工作就算完成了. JobClient 内的静态方法 runJob()会提交作业并等待它完成,把进展情况写入控制台.
waitForCompletion()方法的返回值是一个布尔型true表示成功,false表示失败,即我们翻译成0或1程序的退出代码。
Application to find the maximum temperature in the weather dataset的更多相关文章
- hadoop-mongo map/reduce java
官方 http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-hadoop/ mongo-haoop项目地址 https://g ...
- 【springboot】之Application配置
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- springBoot配置文件application.properties
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- spring-boot默认的application.properties属性
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- springboot成神之——application.properties所有可用属性
application.properties所有可用属性 # =================================================================== # ...
- Spring Boot Common application properties(转载)
转自官方文档:http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.h ...
- 【spring boot】application.properties官方完整文档【参考使用】
官方地址: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ 进入搜索: Appendice ...
- Spring boot application.properties 配置
原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...
- Architecture of Device I/O Drivers, Device Driver Design
http://www.kalinskyassociates.com/Wpaper4.html Architecture of Device I/O Drivers Many embedded syst ...
随机推荐
- 一个Sqrt谋杀触发功能
我们平时常常会有一些数据运算的操作,须要调用sqrt,exp,abs等函数,那么时候你有没有想过:这个些函数系统是怎样实现的?就拿最常常使用的sqrt函数来说吧.系统怎么来实现这个常常调用的函数呢? ...
- Android NDK 简单介绍、工具安装、环境配置
NDK全称:Native Development Kit. 1.NDK是一系列工具的集合. * NDK提供了一系列的工具,帮助开发人员高速开发C(或C++)的动态库,并能自己主动将so和java应用一 ...
- 优化Java堆大小5温馨提示
总结:Java没有足够的堆大小可能会导致性能非常大的影响,这无疑将给予必要的程序,并不能带来麻烦.本文总结了影响Java居前五位的能力不足,并整齐地叠优化? 笔者Pierre有一个10高级系统架构师有 ...
- 内省(二)之BeanUtils工具类
上一篇内省(Introspector)讲到的是采用JavaAPI中的类来操作bean及其属性,而Apache也开源了第三方框架来简化和丰富了对bean属性的操作,这个框架就是BeanUtils. 使用 ...
- find-a-jar-file-given-the-class-name
Save this as findclass.sh (or whatever), put it on your path and make it executable: #!/bin/sh find ...
- JavaScript快速入门(六)——DOM
概念扫盲 DOM DOM是 Document Object Model(文档对象模型)的缩写,是W3C(万维网联盟)的标准.DOM 定义了访问 HTML 和 XML 文档的标准:“W3C 文档对象模型 ...
- Taking Pictures Using FireMonkey Interfaces
http://docwiki.embarcadero.com/RADStudio/Seattle/en/Taking_Pictures_Using_FireMonkey_Interfaces
- ubuntu安装iscsi
ubuntu安装iscsi target端:apt-get install iscsitarget ubuntu安装iscsi initiator端:apt-get install open-iscs ...
- HDU 4296 Buildings (YY)
题意: 给定N个物体,每个物体有两个参数w,s. w代表它自身的重量: s代表它的强度.现在要把这些物体叠在一起,会产生一个PDV值. PDV解释:(Σwj)-si, where (Σwj) st ...
- zip非暴力破解
大家最熟悉的zip破解方式应该是暴力破解,暴力破解有很大局限性,如果密码很长很复杂你很可能一辈子都破解不出来.由于今天要破解自己以前加密过的zip文件,我设的密码习惯性长而复杂,果断放弃暴力破解,在网 ...