是否可以配置Hive的UDF? [英] Is it possible to configure a Hive's UDF?
问题描述
我该如何从自定义Hive的UDF访问外部资源(数据库),将凭证传递给UDF的最佳方法是什么?
I what to access an external resource (database) from a custom Hive's UDF, what is the best way to pass credentials to the UDF?
我试图通过SET设置属性:
I tried to set properties via SET:
SET my.udf.credentials=...;
SELECT myUdf(someColumn) FROM someTable;
并通过GenericUDAFEvaluator的init方法通过HiveConf访问它们,但是它不起作用.有什么建议吗?
and to access them via HiveConf in a GenericUDAFEvaluator's init method, but it doesn't work. Any suggestions?
推荐答案
我希望您正在使用Hive-0.11.
I hope you're using Hive-0.11.
GenericUDAFEvaluator
class has the method configure(MapredContext).
To quote a great man:
另外在之前使用MapredContext设置GenericUDAFEvaluator初始化.仅在MapRedTask的运行时中调用它.
Additionally setup GenericUDAFEvaluator with MapredContext before initializing. This is only called in runtime of MapRedTask.
MapredContext
类具有方法 JobConf
类具有方法将它们放在一起:
public void configure(MapredContext mapredContext) {
String credentials = mapredContext.getJobConf().get("my.udf.credentials");
}
这篇关于是否可以配置Hive的UDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!