Hadoop Tool接口详解

本文详细介绍了HadoopTool接口的功能和使用方式,包括其作为Map-Reduce工具的标准接口的角色,如何处理命令行参数,以及一个具体的实现案例。通过本文,读者可以深入理解HadoopTool接口在Hadoop生态系统中的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Hadoop Tool接口详解

1. 详解
1.1 简介
public interface Tool
extends Configurable

继承自Configurable的接口。

1.2 释义

A tool interface that supports handling of generic command-line options.
Tool, is the standard for any Map-Reduce tool/application. The tool/application should delegate the handling of standard command-line options to ToolRunner.run(Tool, String[]) and only handle its custom arguments.

一个tool 接口用于支持处理普通的命令行参数。
Tool,代表的是任何抽象的Map-Reduce 工具/应用。Tool/application应该代表 ToolRunner.run(Tool,String[]) 标准命令行的处理,以及处理自定义的参数。

Here is how a typical Tool is implemented.

如下是一个典型的Tool实现

         public class MyApp extends Configured implements Tool {
         
           public int run(String[] args) throws Exception {
             // Configuration processed by ToolRunner
             Configuration conf = getConf();
             
             // Create a JobConf using the processed conf
             JobConf job = new JobConf(conf, MyApp.class);
             
             // Process custom command-line options
             Path in = new Path(args[1]);
             Path out = new Path(args[2]);
             
             // Specify various job-specific parameters     
             job.setJobName("my-app");
             job.setInputPath(in);
             job.setOutputPath(out);
             job.setMapperClass(MyMapper.class);
             job.setReducerClass(MyReducer.class);

             // Submit the job, then poll for progress until the job is complete
             RunningJob runningJob = JobClient.runJob(job);
             if (runningJob.isSuccessful()) {
               return 0;
             } else {
               return 1;
             }
           }
           
           public static void main(String[] args) throws Exception {
             // Let ToolRunner handle generic command-line options 
             int res = ToolRunner.run(new Configuration(), new MyApp(), args);
             
             System.exit(res);
           }
         }    

继承了Configured类,实现了Tool接口。

2. 方法详解
  • run(String[] args)
    在这里插入图片描述
  • getConf()setConf方法
    这两个方法都是从Configurable接口中继承下来的。
3. 实战案例

此处略

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

说文科技

看书人不妨赏个酒钱?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值