瑣碎-關於hadoop的GenericOptionsParser類



GenericOptionsParser 命令行解析器

是hadoop框架中解析命令行參數的基本類。它能夠辨別一些標准的命令行參數,能夠使應用程序輕易地指定namenode,jobtracker,以及其他額外的配置資源

有篇日志寫的很好,自己就不贅述了:http://www.cnblogs.com/caoyuanzhanlang/archive/2013/02/21/2920934.html


 

例子:

最簡單的在WordCount中用到了:

 1     Configuration conf = new Configuration();
 2     String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
 3     if (otherArgs.length != 2) {
 4       System.err.println("Usage: wordcount <in> <out>");
 5       System.exit(2);
 6     }
 7     Job job = new Job(conf, "word count");
 8     job.setJarByClass(WordCount.class);
 9     job.setMapperClass(TokenizerMapper.class);
10     job.setCombinerClass(IntSumReducer.class);
11     job.setReducerClass(IntSumReducer.class);
12     job.setOutputKeyClass(Text.class);
13     job.setOutputValueClass(IntWritable.class);
14     FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
15     FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
16     System.exit(job.waitForCompletion(true) ? 0 : 1);

比如運行命令為:bin/hadoop dfs -fs master:8020 -ls /data

GenericOptionsParser把  -fs master:8020配置到配置conf中

而getRemainingArgs()方法則得到剩余的參數,就是 -ls /data。供下面使用輸入輸出參數


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM