琐碎-关于hadoop的GenericOptionsParser类

王朝学院·作者佚名  2016-05-29
窄屏简体版  字體: 小  |  中  |  大  |  超大  

琐碎-关于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。供下面使用输入输出参数

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航