java - 调用作业的区别

标签 java hadoop mapreduce

main() 和从 ToolRunner.run() 调用 mapreduce 作业有什么区别?当我们说主类说 MapReduce extends Configured implements Tool 时,如果我们只是从 main 方法简单地运行作业,我们得到的额外特权是什么? ?谢谢。

最佳答案

没有额外的权限,但您的命令行选项通过 GenericOptionsParser 运行,这将允许您提取某些配置属性并从中配置配置对象:

http://hadoop.apache.org/common/docs/r0.20.2/api/org/apache/hadoop/util/GenericOptionsParser.html

基本上而不是自己解析一些选项(使用列表中参数的索引),您可以从命令行显式配置配置属性:

hadoop jar myJar.jar com.Main prop1value prop2value

public static void main(String args[]) {
    Configuration conf = new Configuration();
    conf.set("prop1", args[0]);
    conf.set("prop2", args[1]);

    conf.get("prop1"); // will resolve to "prop1Value"
    conf.get("prop2"); // will resolve to "prop2Value"
}

使用 ToolRunner 变得更加简洁:

hadoop jar myJar.jar com.Main -Dprop1=prop1value -Dprop2=prop2value

public int run(String args[]) {
    Configuration conf = getConf();

    conf.get("prop1"); // will resolve to "prop1Value"
    conf.get("prop2"); // will resolve to "prop2Value"
}

不过最后一个警告:当使用 Configuration 方法 getConf() 时,首先创建您的 Job 对象,然后将其 Configuration 拉出 - Job 构造函数会复制传入的 Configruation 对象,因此如果您对传入的引用,您的作业将看不到这些更改:

public int run(String args[]) {
    Configuration conf = getConf();

    conf.set("prop3", "blah");

    Job job = new Job(conf); // job will have a deep copy of conf

    conf.set("prop4", "dummy"); // here we're amending the original conf

    job.getConfiguration().get("prop4"); // will resolve to null
}

关于java - 调用作业的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9859652/

相关文章:

java - SuperCSV 编写器中的不区分大小写的标题?

hadoop - 我可以使用集群复制在两个不同的集群之间进行 Hbase 迁移吗?

hadoop - yarn : How to run MapReduce jobs with lot of mappers comparing to cluster size

ruby - MongoDB 和 MongoRuby : Sorting on mapreduce

java - Android - gson.toJson 在 ArrayList<OverlayItem> 上抛出 StackOverFlowError

java - 有多个 SLF4J 绑定(bind)时如何使用 SLF4J

java - 如何在 Spring 中仅实现 CrudRepository 的特定方法?

apache - 500GB或1TB上的Hadoop 2.6和2.7 Apache Terasort

java - 如何告诉 MapReduce 使用多少个映射器?

java - 我们可以在 mapreduce 代码中将一些计算任务放在映射器类的设置方法中吗