1、设置job的基础属性

Job job = new Job();
job.setJarByClass(***.class);
job.setJobName(“job name”);
job.setNumReduce(2);

2、设置Map与Reudce的类

job.setMappgerClass(*.class);
job.setReduceClass(*.class);

3、设置Job的输入输出格式

 void    setInputFormatClass(Class<? extends InputFormat> cls)

 void    setOutputFormatClass(Class<? extends OutputFormat> cls) 

前者默认是TextInputFormat,后者是FileOutputFormat。

4、设置Job的输入输出路径

当输入输出是文件时,需要指定路径。

InputFormat:
static void addInputPath(JobConf conf, Path path) FileOutputFormat:
static void setOutputPath(Job job, Path outputDir) 

当输入格式是其它类型时,则需要指定相应的属性,如Gora的DataSource。

5、设置map与reduce的输出键值类型

主要有以下4个类

 void    setOutputKeyClass(Class<?> theClass)

 void    setOutputValueClass(Class<?> theClass)

 void    setMapOutputKeyClass(Class<?> theClass)

 void    setMapOutputValueClass(Class<?> theClass) 

(1)前面2个方法设置整个job的输出,即reduce的输出。默认情况下,map的输出类型与reduce一致,若二者不一致,则需要通过后面2个方法来指定map的输出类型。

(2)关于输入类型的说明:reduce的输入类型由output的输出类型决定。map的输入类型由输入格式决定,如输入格式是FileInputFormat,则输入KV类型为LongWriterable与Text。







6、运行程序

job.waitForCompletion()。

见以下示例:

package org.jediael.hadoopdemo.maxtemperature;

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);
}
//1、设置job的基础属性
Job job = new Job();
job.setJarByClass(MaxTemperature.class);
job.setJobName("Max temperature"); //2、设置Map与Reudce的类
job.setMapperClass(MaxTemperatureMapper.class);
job.setReducerClass(MaxTemperatureReducer.class); //4、设置map与reduce的输出键值类型
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class); //5、设置输入输出路径
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1])); //6、运行程序
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

运行一个Hadoop Job所需要指定的属性的更多相关文章

  1. 运行一个Hadoop Job所需要指定的属性 分类: A1_HADOOP 2015-02-02 21:33 231人阅读 评论(0) 收藏

    1.设置job的基础属性 Job job = new Job(); job.setJarByClass(***.class); job.setJobName("job name") ...

  2. 运行第一个Hadoop程序,WordCount

    系统: Ubuntu14.04 Hadoop版本: 2.7.2 参照http://www.cnblogs.com/taichu/p/5264185.html中的分享,来学习运行第一个hadoop程序. ...

  3. Hadoop学习历程(四、运行一个真正的MapReduce程序)

    上次的程序只是操作文件系统,本次运行一个真正的MapReduce程序. 运行的是官方提供的例子程序wordcount,这个例子类似其他程序的hello world. 1. 首先确认启动的正常:运行 s ...

  4. MapReduce扩展:应用程序如何运行于Hadoop Yarn之上

    1. 背景   “应用程序运行于Hadoop Yarn之上”的需求来源于微博运维数据平台中的调度系统,即调度系统中的任务需要运行于Hadoop Yarn之上.这里的应用程序可以简单理解为一个普通的进程 ...

  5. HDFS设计思路,HDFS使用,查看集群状态,HDFS,HDFS上传文件,HDFS下载文件,yarn web管理界面信息查看,运行一个mapreduce程序,mapreduce的demo

    26 集群使用初步 HDFS的设计思路 l 设计思想 分而治之:将大文件.大批量文件,分布式存放在大量服务器上,以便于采取分而治之的方式对海量数据进行运算分析: l 在大数据系统中作用: 为各类分布式 ...

  6. Amazon EMR(Elastic MapReduce):亚马逊Hadoop托管服务运行架构&Hadoop云服务之战:微软vs.亚马逊

    http://s3tools.org/s3cmd Amazon Elastic MapReduce (Amazon EMR)简介 Amazon Elastic MapReduce (Amazon EM ...

  7. 第一个hadoop 程序

    首先检查hadoop是否安装并配置正确然后建立WordCount.java文件里面保存package org.myorg; import java.io.IOException;import java ...

  8. VC只运行一个程序实例

    方法有很多,以下只是提供一种用的多的 一. 单文档程序 在程序App类的InitInstance中添加如下代码 BOOL CDDZApp::InitInstance() { /*只运行一个实例*/ / ...

  9. 【云计算】K8S DaemonSet 每个node上都运行一个pod

    Kubernetes容器集群中的日志系统集成实践 Kubernetes是原生的容器编排管理系统,对于负载均衡.服务发现.高可用.滚动升级.自动伸缩等容器云平台的功能要求有原生支持.今天我分享一下我们在 ...

随机推荐

  1. Readonly and other things about C++

    1. in c# readonly can be delayed to initialize in constructor. 2. in c++ totally no readonly. Many p ...

  2. 编译recovery及过程中的部分错误解决

    你必须使用32位或64位Ubuntu系统,关于如何建立编译环境和同步源码的指导,请自己查找有关指导的文章. 1, 安装所需要的包 2, 建立编译的环境,并同步CWM所需的源码,CyanogenMod源 ...

  3. VIM下Express jade空格问题:expected "indent", but got "newline"

    Error: /home/y/my_note/nodejs/myapp/views/index.jade: | -list=[{name:,email:'zhangsan@123.com'}] | - ...

  4. DOCKER功能练习

    都是书上的示例,慢慢进入..

  5. NGINX的CORS--跨域访问配置

    阻止交叉源访问问题. 网上可搜N多,解决办法都差不多,其中一种: add_header Access-Control-Allow-Origin http://xxxx:port; add_header ...

  6. logstash 利用drop 丢弃过滤日志

    input { stdin { } } filter { grok { match => ["message","\s*%{TIMESTAMP_ISO8601}\s ...

  7. ubuntu记录

    1. gleboneblack OMAPES=4.x ANDROID_ROOT_DIR=$HOME/aosp W=1 install /bin/sh: 5: ./install.sh: Permiss ...

  8. hdu 1695 GCD(欧拉函数+容斥)

    Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...

  9. vbox下centos安装增加功能失败

    一般都是:unable to find the sources of your current Linux kernel. 先尝试这个吧:yum install kernel kernel-heade ...

  10. css中的段落样式及背景

    一.段落样式 css中关于段落的样式主要有行高,缩进,段落对齐,文字间距,文字溢出,段落换行等.它们的具体语法如下: line-height : normal | length text-indent ...