我想将hive变量传递给hive。
下面是一个代码片段。
hive -f ../hive/testHive.sql -hivevar testArg=${testArg}下面是蜂巢UDF呼叫。
select setUserDefinedValueForColumn(columnName,'${testArg}') from testTable;在udf中,我将testArg的值作为null。
请告诉我如何在UDF中使用hive变量,以及如何访问Hive中的hive配置?
发布于 2018-10-01 22:41:13
我认为您应该使用以下命令将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);
}
}代码在hive1.2上进行了测试
发布于 2018-05-18 13:08:58
不能在视图代码中使用${hiveconf:testArg}将Hive变量直接传递给视图,因为在视图创建过程中,Hive将接受变量的确切值,因此视图将是静态的。
唯一的机会是使用UDF访问hive变量:
您可以使用GenericUDF。它有一个以MapredContext为参数的方法配置。因此,您需要在GenericUDF中指定一个配置方法,例如:
public void configure(MapredContext context){
yourVar = context.getJobConf().get("hive_variable");
}这只在MapRedTask的运行时被调用。
https://stackoverflow.com/questions/23995290
复制相似问题