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. 错误日志类C#

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  2. .NET知识点总结二(笔记整合)

    19.什么是类型? 用来定义某一种数据在内存里开辟空间的大小,还可以预置操作此种类型数据的相关方法 20.this关键字在方法中使用时所代表的含义 this指的是当前类的对象,或者父类的类的对象(ba ...

  3. ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题

    ios7中使用scrollview来横向滑动图片,自动产生偏移竖向的偏移 问题     如图红色为scrollview的背景色,在scrollview上加了图片之后,总会有向下的偏移 设置conten ...

  4. Swift类和结构体定义-备

    Swift中的类和结构体定义的语法是非常相似的.类使用class关键词定义类,使用struct关键词定义结构体,它们的语法格式如下: class 类名 { 定义类的成员 } struct 结构体名 { ...

  5. 树上莫队 wowow

    构建:像线性的莫队那样,依旧是按sqrt(n)为一块分块. int dfs(int x){ ; dfn[x]=++ind; ;i<=;i++) if (bin[i]<=deep[x]) f ...

  6. Unity性能优化

    一.优化组件访问方式 原文:http://blog.csdn.net/lijing_hi/article/details/11657887 1.缓存Component的引用,如transform 2. ...

  7. poj 2392 Space Elevator(多重背包+先排序)

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  8. 20 个非常棒的jQuery内容滑动插件

    Wow Slider  WOW Slider是一款小巧易用的网页滑块设计.该软件内置大量的模版和工具,让你轻松设计出完美的视觉效果.他还可以帮助用户在短时间内创造出梦幻般的滑块,而无需编码和图像编辑, ...

  9. 最全的js正则表达式用法大全

    匹配中文字符的正则表达式: [u4e00-u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^x00-xff] 评注:可以用来计算字符串的长度(一 ...

  10. asp.net页面之间的跳转

    调用Request.CurrentExecutionFilePath方法返回到当前页面 站点中常常要跳转页面,调用Request.CurrentExecutionFilePath方法能够获取当前页面的 ...