有没有办法将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. 如何将系统属性传递给gradle任务
- 4. 如何将系统属性文件传递给GWT?
- 5. 如何将java系统属性传递给码头?
- 6. 如何将系统属性传递给jar文件
- 7. 如何将系统属性传递给码头集装箱?
- 8. 如何将Java系统属性传递给货运集装箱
- 9. 将数据属性传递给函数
- 10. Haskell - 将参数传递给map函数?
- 11. 将javascript属性传递给javascript函数
- 12. 将函数传递给css属性
- 13. 如何将属性传递给JavaScript中的变量函数?
- 14. 如何将属性传递给同一个类中的函数?
- 15. 将值传递给map函数--CouchDB
- 16. 如何通过R将系统函数传递给monetdb?
- 17. 如何系统属性传递给Java小程序的HTML
- 18. 未将系统属性传递给Java虚拟机的Maven 2.1.0
- 19. 如何将setter属性作为参数传递给函数?
- 20. 如何将动态属性作为参数传递给函数?
- 21. l_ply:如何将列表的名称属性传递给函数?
- 22. 如何将$ _POST的属性传递给函数?
- 23. 如何在intelliJ IDE中将系统属性传递给Maven测试
- 24. 将系统属性传递给可执行文件
- 25. 在将属性传递给函数后,获取属性的属性,如参考
- 26. 是否可以将属性从mapper传递给hadoop中的reducer?
- 27. 如何将JS函数作为对象属性传递给iOS
- 28. 如何将JSF托管bean属性传递给JavaScript函数?
- 29. 如何将自定义属性传递给函数?
- 30. 如何将EL函数调用传递给复合属性?
所以,你想一个属性文件传递给每一个映射器的? –
是的。让我再解释一下。我们的映射器正在访问HBase中的数据,这意味着我们需要在映射函数中创建配置。为了测试等目的,我们不需要配置硬编码。我不确定如果这是最好的方法,如果有更好的方法来整合HBase hadoop mapreduce。代码中缺少进口 – jaksky