我想将配置单元conf变量传递给配置单元UDF。
下面是一个代码片段。
hive -f ../hive/testHive.sql -hivevar testArg=${testArg}
下面是配置单元UDF调用。
select setUserDefinedValueForColumn(columnName,'${testArg}') from testTable;
在udf中,我将testArg的值设置为null。
请告诉我如何在udf中使用hive conf变量,以及如何在hive UDF中访问Hive配置?
我认为您应该使用以下命令将hive变量作为“ hiveconf”传递:
hive --hiveconf testArg="my test args" -f ../hive/testHive.sql
然后,您可能在GenericUDF evaluate()
方法中包含以下代码:
@Override
public Object evaluate(DeferredObject[] args) throws HiveException {
String myconf;
SessionState ss = SessionState.get();
if (ss != null) {
HiveConf conf = ss.getConf();
myconf= conf.get("testArg");
System.out.println("sysout.myconf:"+ myconf);
}
}
该代码已在Hive 1.2上进行了测试
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句