博客
关于我
运行一个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
你可能感兴趣的文章
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>