博客
关于我
运行一个Hadoop Job所需要指定的属性
阅读量:83 次
发布时间:2019-02-26

本文共 2210 字,大约阅读时间需要 7 分钟。

1、设置job的基础属性
[java] 
 
  1. Job job = new Job();  
  2. job.setJarByClass(***.class);  
  3. job.setJobName(“job name”);  
  4. job.setNumReduce(2);  
2、设置Map与Reudce的类
[java] 
 
  1. job.setMappgerClass(*.class);  
  2. job.setReduceClass(*.class);  

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

[java] 
 
  1. void    setInputFormatClass(Class<? extends InputFormat> cls)  
  2.   
  3. void    setOutputFormatClass(Class<? extends OutputFormat> cls)   

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

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

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

[java] 
 
  1. InputFormat:  
  2. static void    addInputPath(JobConf conf, Path path)  
  3.   
  4. FileOutputFormat:  
  5. static void    setOutputPath(Job job, Path outputDir)   
当输入格式是其它类型时,则需要指定相应的属性,如Gora的DataSource。

5、设置map与reduce的输出键值类型
主要有以下4个类
[java] 
 
  1. void    setOutputKeyClass(Class<?> theClass)  
  2.   
  3. void    setOutputValueClass(Class<?> theClass)  
  4.   
  5. void    setMapOutputKeyClass(Class<?> theClass)  
  6.   
  7. void    setMapOutputValueClass(Class<?> theClass)   
(1)前面2个方法设置整个job的输出,即reduce的输出。默认情况下,map的输出类型与reduce一致,若二者不一致,则需要通过后面2个方法来指定map的输出类型。
(2)关于输入类型的说明:reduce的输入类型由output的输出类型决定。map的输入类型由输入格式决定,如输入格式是FileInputFormat,则输入KV类型为LongWriterable与Text。
6、运行程序

job.waitForCompletion()。

见以下示例:

[java] 
 
  1. package org.jediael.hadoopdemo.maxtemperature;  
  2.   
  3. import org.apache.hadoop.fs.Path;  
  4. import org.apache.hadoop.io.IntWritable;  
  5. import org.apache.hadoop.io.Text;  
  6. import org.apache.hadoop.mapreduce.Job;  
  7. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;  
  8. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;  
  9.   
  10. public class MaxTemperature {  
  11.     public static void main(String[] args) throws Exception {  
  12.         if (args.length != 2) {  
  13.             System.err  
  14.                     .println("Usage: MaxTemperature <input path> <output path>");  
  15.             System.exit(-1);  
  16.         }  
  17.         //1、设置job的基础属性  
  18.         Job job = new Job();  
  19.         job.setJarByClass(MaxTemperature.class);  
  20.         job.setJobName("Max temperature");  
  21.   
  22.         //2、设置Map与Reudce的类  
  23.         job.setMapperClass(MaxTemperatureMapper.class);  
  24.         job.setReducerClass(MaxTemperatureReducer.class);  
  25.           
  26.         //4、设置map与reduce的输出键值类型  
  27.         job.setOutputKeyClass(Text.class);  
  28.         job.setOutputValueClass(IntWritable.class);  
  29.           
  30.         //5、设置输入输出路径  
  31.         FileInputFormat.addInputPath(job, new Path(args[0]));  
  32.         FileOutputFormat.setOutputPath(job, new Path(args[1]));  
  33.           
  34.         //6、运行程序  
  35.         System.exit(job.waitForCompletion(true) ? 0 : 1);  
  36.     }  
  37. }  

版权声明:本文为博主原创文章,转载请注明来自http://blog.csdn.net/jediael_lu/ https://blog.csdn.net/jediael_lu/article/details/43416751
你可能感兴趣的文章
NISP一级,NISP二级报考说明,零基础入门到精通,收藏这篇就够了
查看>>
NISP国家信息安全水平考试,收藏这一篇就够了
查看>>
NIS服务器的配置过程
查看>>
NIS认证管理域中的用户
查看>>
Nitrux 3.8 发布!性能全面提升,带来非凡体验
查看>>
NiuShop开源商城系统 SQL注入漏洞复现
查看>>
NI笔试——大数加法
查看>>
NLog 自定义字段 写入 oracle
查看>>
NLog类库使用探索——详解配置
查看>>
NLP 基于kashgari和BERT实现中文命名实体识别(NER)
查看>>
NLP 模型中的偏差和公平性检测
查看>>
Vue3.0 性能提升主要是通过哪几方面体现的?
查看>>
NLP 项目:维基百科文章爬虫和分类【01】 - 语料库阅读器
查看>>
NLP_什么是统计语言模型_条件概率的链式法则_n元统计语言模型_马尔科夫链_数据稀疏(出现了词库中没有的词)_统计语言模型的平滑策略---人工智能工作笔记0035
查看>>
NLP、CV 很难入门?IBM 数据科学家带你梳理
查看>>
NLP三大特征抽取器:CNN、RNN与Transformer全面解析
查看>>
NLP入门(六)pyltp的介绍与使用
查看>>
NLP学习笔记:使用 Python 进行NLTK
查看>>
NLP度量指标BELU真的完美么?
查看>>
NLP的不同研究领域和最新发展的概述
查看>>