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?
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");
}