Hadoop Tool介面詳解
阿新 • • 發佈:2018-12-27
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. 實戰案例
此處略