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 ...
随机推荐
- HDU--杭电--3790--最短路径问题
最短路径问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- twemproxy 简介
twemproxy,也叫nutcraker.是twtter开源的一个redis和memcache代理服务器. redis作为一个高效的缓存服务器,非常具有应用价值.但是当使用比较多的时候,就希望可以通 ...
- Nginx负载均衡:分布式/热备Web Server的搭建
Nginx是一款轻量级的Web server/反向代理server及电子邮件(IMAP/POP3)代理server.并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开 ...
- OCP-1Z0-051-题目解析-第33题
33. You want to create an ORD_DETAIL table to store details for an order placed having the following ...
- Android中Activity之间访问互传参数
public class MainActivity extends Activity { private static final int OTHER = 1; @Override protected ...
- [课堂实践与项目]IOS只能进行简单的加减乘除的没有优先级的计算器
// // LCViewController.m // calculator // // Created by lichan on 13-12-3. // Copyright (c) 2013年 co ...
- Eclipse TestNg插件
TestNg作为一个测试框架,也有eclipse的插件: 官网给的安装插件地址是 : For Eclipse 3.4 and above, enter http://beust.com/eclipse ...
- Servlet过滤器——日志记录过滤器
1.概述 在实际的项目开发过程中,经常需要在项目运行时,记录并在控制台中输出运行时的日志信息,便于查看项目的运行状况.本实例将介绍如何应用过滤器实现日志记录.运行本实例,将在控制台中输出项目运行时的日 ...
- poj 3211 Washing Clothes(背包)
很不错的01背包!!! 不过有点疑问!!!(注释) #include <algorithm> #include<stdio.h> #include<string.h> ...
- hdu 4687 带花树匹配
其实吧,思路挺简单的,只不过昨天刚学,还有一些东西不太了解,然后就23333333... 吃晚饭回来就A了,我是有多傻啊,这么题都A不掉,不能忍啊... 我们可以先求出哪些边是可能存在于最大匹配中的, ...