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的更多相关文章

  1. hadoop-mongo map/reduce java

    官方 http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-hadoop/ mongo-haoop项目地址 https://g ...

  2. 【springboot】之Application配置

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  3. springBoot配置文件application.properties

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  4. spring-boot默认的application.properties属性

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  5. springboot成神之——application.properties所有可用属性

    application.properties所有可用属性 # =================================================================== # ...

  6. Spring Boot Common application properties(转载)

    转自官方文档:http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.h ...

  7. 【spring boot】application.properties官方完整文档【参考使用】

    官方地址: https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ 进入搜索: Appendice ...

  8. Spring boot application.properties 配置

    原文链接: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.ht ...

  9. Architecture of Device I/O Drivers, Device Driver Design

    http://www.kalinskyassociates.com/Wpaper4.html Architecture of Device I/O Drivers Many embedded syst ...

随机推荐

  1. Python Challenge 第四题

    这一题没有显示提示语,仅仅有一幅图片,图片也看不出什么名堂,于是直接查看源代码,源代码例如以下: <html> <head> <title>follow the c ...

  2. MongoDB系列之三(副本集配置)

    今天我测试了一下MongoDB的副本集的配置. 首先从概念上说一下MongoDB副本集和主从复制的区别.其实副本集(Replica Set)是主从复制的高级形式.高级在哪里呢?主动复制实现了数据备份+ ...

  3. sql: sybase与oracle中insert into select和select into的用法

    1. sybase与oracle中insert into select和select into的用法 http://wjlvivid.iteye.com/blog/1921679 Sybase 一.首 ...

  4. perl 匿名函数传参

    $subref=sub { my $a=shift; return $a; }; print $subref->("xxyyzz");

  5. jqueryui datepicker refresh

    http://stackoverflow.com/questions/6056287/jquery-ui-datepicker-prevent-refresh-onselect 给选中的TD加背景色

  6. 浅谈C#中的泛型

    1.什么是泛型? 泛型是程序设计语言的一种特性.允许程序员在强类型程序设计语言中编写 代码时定义一些可变部分,那些部分在使用前必须作出指明.各种程序设计语言和其编译器.运行环境对泛型的支持均不一样.将 ...

  7. robotframework ride 版本兼容问题

    在安装robotFramework ride的时候,必须需要使用wxpython 目前使用的wxpython 还必须是unicode 版本的要不然不支持中文 目前使用的 wx.version.2.8. ...

  8. Mfc资源消息的响应机制

    Mfc消息的响应机制 Mfc中有很多资源,如图标资源,菜单资源,工具栏资源等等:那么,资源是如何进行消息响应和消息映射的呢? 它们的流程是: 某种资源——对应的ID号——消息映射——响应函数的声明与实 ...

  9. 【转】有效修改max open files/ulimit -n

    [转]有效修改max open files/ulimit -n_追梦20121222_新浪博客     [转]有效修改max open files/ulimit -n    (2011-11-18 0 ...

  10. PowerDesigner反projectM连接ySql没有mySql odbc驱动器

    PowerDesignerfang反project连接MySql没有mySql odbc驱动器 需要安装 MySql ODBC驱动器.百度下载mysql-connector-odbc-5.3.4-wi ...