博客
关于我
运行一个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
你可能感兴趣的文章
nat 网卡间数据包转发_你是不是从来没有了解过光纤网卡,它跟普通网卡有什么区别?...
查看>>
NAT-DDNS内网穿透技术,快解析DDNS的优势
查看>>
NAT-DDNS内网穿透技术,快解析DDNS的优势
查看>>
NAT-DDNS内网穿透技术,解决动态域名解析难题
查看>>
natapp搭建外网服务器
查看>>
NativePHP:使用PHP构建跨平台桌面应用的新框架
查看>>
nativescript(angular2)——ListView组件
查看>>
NativeWindow_01
查看>>
Native方式运行Fabric(非Docker方式)
查看>>
Nature | 电子学“超构器件”, 从零基础到精通,收藏这篇就够了!
查看>>
Nature和Science同时报道,新疆出土四千年前遗骸完成DNA测序,证实并非移民而是土著...
查看>>
Nature封面:只低一毫米,时间也会变慢!叶军团队首次在毫米尺度验证广义相对论...
查看>>
Nat、端口映射、内网穿透有什么区别?
查看>>
Nat、端口映射、内网穿透有什么区别?
查看>>
nat打洞原理和实现
查看>>
NAT技术
查看>>
NAT模式/路由模式/全路由模式 (转)
查看>>
NAT模式下虚拟机centOs和主机ping不通解决方法
查看>>
NAT的两种模式SNAT和DNAT,到底有啥区别?
查看>>
NAT的全然分析及其UDP穿透的全然解决方式
查看>>