Is it possible to configure a Hive's UDF?

2019-08-01 03:29发布

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?

I tried to set properties via SET:

SET my.udf.credentials=...;
SELECT myUdf(someColumn) FROM someTable;

and to access them via HiveConf in a GenericUDAFEvaluator's init method, but it doesn't work. Any suggestions?

标签: hive
1条回答
做自己的国王
2楼-- · 2019-08-01 04:01

I hope you're using Hive-0.11.

GenericUDAFEvaluator class has the method configure(MapredContext). To quote a great man:

Additionally setup GenericUDAFEvaluator with MapredContext before initializing. This is only called in runtime of MapRedTask.

MapredContext class has the method getJobConf.

JobConf class has the method get.

Putting it all together:

public void configure(MapredContext mapredContext) {
  String credentials = mapredContext.getJobConf().get("my.udf.credentials");
}
查看更多
登录 后发表回答