博客
关于我
运行一个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/

你可能感兴趣的文章
Notepad ++ 安装与配置教程(非常详细)从零基础入门到精通,看完这一篇就够了
查看>>
Notepad++在线和离线安装JSON格式化插件
查看>>
notepad++最详情汇总
查看>>
notepad++正则表达式替换字符串详解
查看>>
notepad如何自动对齐_notepad++怎么自动排版
查看>>
Notes on Paul Irish's "Things I learned from the jQuery source" casts
查看>>
Notification 使用详解(很全
查看>>
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
查看>>
NotImplementedError: Could not run torchvision::nms
查看>>
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! fatal: unable to connect to github.com:
查看>>
npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>