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

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

Java MapReduce Job配置指南

1. Job基础属性设置

创建一个新的Job实例,并配置其基础属性。可以通过以下步骤实现:

Job job = new Job();job.setJarByClass(YourClass.class);job.setJobName("your_job_name");job.setNumReduce(2); // 设置并行度

2. Map/Reduce类设置

配置Map和Reduce的类,提供默认的处理类或自定义类:

job.setMapperClass(YourMapperClass.class);job.setReducerClass(YourReducerClass.class);

3. 输入输出格式设置

指定Job的输入和输出格式,默认为TextInputFormat和FileOutputFormat:

job.setInputFormatClass(InputFormat.class);job.setOutputFormatClass(OutputFormat.class);

4. 输入输出路径设置

当使用文件输入或输出时,指定相应路径:

FileInputFormat.addInputPath(job, new Path("输入路径"));FileOutputFormat.setOutputPath(job, new Path("输出路径"));

5. 输出键值类型设置

配置Map和Reduce的输出键值类型,提供四个主要类别:

// Map输出job.setOutputKeyClass(YourKeyClass.class);job.setOutputValueClass(YourValueClass.class);// Reduce输出(默认与Map输出一致)

6. 运行程序

提交Job进行处理,并等待完成:

job.waitForCompletion();

示例代码

import org.apache.hadoop.fs.Path;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 {        // 1. 设置Job基础属性        Job job = new Job();        job.setJarByClass(MaxTemperature.class);        job.setJobName("Max temperature");        job.setNumReduce(2);        // 2. 设置Map/Reduce类        job.setMapperClass(MaxTemperatureMapper.class);        job.setReducerClass(MaxTemperatureReducer.class);        // 3. 设置输入输出格式        job.setInputFormatClass(FileInputFormat.class);        job.setOutputFormatClass(FileOutputFormat.class);        // 4. 设置输入输出路径        FileInputFormat.addInputPath(job, new Path(args[0]));        FileOutputFormat.setOutputPath(job, new Path(args[1]));        // 5. 设置输出键值类型        job.setOutputKeyClass(Text.class);        job.setOutputValueClass(IntWritable.class);        // 6. 运行程序        System.exit(job.waitForCompletion(true) ? 1 : 0);    }}

注意:上述示例为伪代码,实际开发中需根据需要导入相应的类和包。

转载地址:http://gqnk.baihongyu.com/

你可能感兴趣的文章
php基本符号大全
查看>>
php基础篇-二维数组排序 array_multisort
查看>>
php基础配置环境变量
查看>>
php增删改查封装方法
查看>>
springboot之jar包Linux后台启动部署及滚动日志查看且日志输出至文件保存(超级详细)
查看>>
php多条件筛选功能的实现
查看>>
php多线程
查看>>
PHP大数组循环-避免产生Notice或者是Warning
查看>>
PHP大数组过滤元素、修改元素性能分析
查看>>
PHP大文件切片下载代码
查看>>
PHP如何下载远程文件到指定目录
查看>>
php如何优化压缩的图片
查看>>
php如何做表格,新手怎么制作表格
查看>>
RabbitMQ高级特性
查看>>
php如何定义的数位置,php如何实现不借助IDE快速定位行数或者方法定义的文件和位置...
查看>>
RabbitMQ集群 - 普通集群搭建、宕机情况
查看>>
php如何正确的获得文件的后缀名
查看>>
PHP如何生成唯一的数字ID
查看>>
PHP如何获取当前页面的最后修改时间
查看>>
PHP如何读取json数据
查看>>