有没有办法将hadoop map reduce框架中的系统参数(如-Dmy_param = XXX)传递给map函数。 通过.setJarByClass()完成向hadoop集群提交作业。 在映射器中,我必须创建配置,所以我想使它变得可控,所以我认为通过属性文件的标准方式可以。只需在设置属性的时候传递参数就可以了。另一种方法是将属性文件添加到提交的jar文件中。有人有经验如何解决这个问题吗?如何将系统属性传递给hadoop中的map函数
2
A
回答
7
如果您尚未在作业中使用此功能,则可以尝试运行Hadoop作业的GenericOptionsParser,Tool和ToolRunner。
注意: MyDriver扩展配置并实现工具。 而且,运行您工作中使用这个
hadoop -jar somename.jar MyDriver -D your.property=value arg1 arg2
欲了解更多信息,check this link。
这是我为你准备了一些示例代码:
public class MyDriver extends Configured implements Tool {
public static class MyDriverMapper extends Mapper<LongWritable, Text, LongWritable, NullWritable> {
protected void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
// In the mapper you can retrieve any configuration you've set
// while starting the job from the terminal as shown below
Configuration conf = context.getConfiguration();
String yourPropertyValue = conf.get("your.property");
}
}
public static class MyDriverReducer extends Reducer<LongWritable, NullWritable, LongWritable, NullWritable> {
protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context)
throws IOException, InterruptedException {
// --- some code ---
}
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new MyDriver(), args);
System.exit(exitCode);
}
@Override
public int run(String[] args) throws Exception {
Configuration conf = getConf();
// if you want you can get/set to conf here too.
// your.property can also be file location and after
// you retrieve the properties and set them one by one to conf object.
// --other code--//
Job job = new Job(conf, "My Sample Job");
// --- other code ---//
return (job.waitForCompletion(true) ? 0 : 1);
}
}
+0
。链接是404.配置类的包是什么? – harschware
相关问题
- 1. 将系统属性传递给`sbt console`?
- 2. 如何将值传递给XV6中的系统调用函数?
- 3. 如何将系统属性文件传递给GWT?
- 4. 如何将Java系统属性传递给货运集装箱
- 5. 如何将系统属性传递给jar文件
- 6. 如何将java系统属性传递给码头?
- 7. 将数据属性传递给函数
- 8. Haskell - 将参数传递给map函数?
- 9. 将javascript属性传递给javascript函数
- 10. 将函数传递给css属性
- 11. 如何将属性传递给JavaScript中的变量函数?
- 12. 将值传递给map函数--CouchDB
- 13. 如何系统属性传递给Java小程序的HTML
- 14. 未将系统属性传递给Java虚拟机的Maven 2.1.0
- 15. 如何将setter属性作为参数传递给函数?
- 16. l_ply:如何将列表的名称属性传递给函数?
- 17. 如何将$ _POST的属性传递给函数?
- 18. 如何在intelliJ IDE中将系统属性传递给Maven测试
- 19. 在将属性传递给函数后,获取属性的属性,如参考
- 20. 如何将JSF托管bean属性传递给JavaScript函数?
- 21. 如何将自定义属性传递给函数?
- 22. 如何将EL函数调用传递给复合属性?
- 23. 如何将函数和值传递给onchange HTML属性?
- 24. 如何将Map传递给Oracle PL/SQL函数?
- 25. 如何将map函数传递给自定义组件?
- 26. 如何将变量从.map()传递给回调函数
- 27. 如何将ControllerContext传递给属性
- 28. 将字符串数组传递给系统函数?
- 29. 如何将系统属性从jruby传递到Rails服务器
- 30. 如何通过map函数将函数属性传递给子/孙子? (并从状态删除项目)
所以,你想一个属性文件传递给每一个映射器的? –
是的。让我再解释一下。我们的映射器正在访问HBase中的数据,这意味着我们需要在映射函数中创建配置。为了测试等目的,我们不需要配置硬编码。我不确定如果这是最好的方法,如果有更好的方法来整合HBase hadoop mapreduce。代码中缺少进口 – jaksky