如何在 hive udf 中传递 Hive conf 变量? [英] How to pass Hive conf variable in hive udf?

查看:40
本文介绍了如何在 hive udf 中传递 Hive conf 变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 hive conf 变量传递给 hive UDF.

I want to pass hive conf variable to hive UDF.

下面是代码片段.

hive -f ../hive/testHive.sql -hivevar testArg=${testArg}

下面是 hive UDF 调用.

Below is hive UDF call.

select setUserDefinedValueForColumn(columnName,'${testArg}') from testTable;

在 udf 中,我将 testArg 的值设为 null.

In udf I am getting value of testArg as null.

请教我如何在 udf 中使用 hive conf 变量以及如何在 hive UDF 中访问 Hive 配置?

Please advice me how to use hive conf variable in udf and how to access Hive configuration in hive UDF?

推荐答案

我认为您应该使用以下命令将 hive 变量作为 'hiveconf' 传递:

I think that you should pass hive variable as 'hiveconf' using below command:

hive --hiveconf testArg="my test args" -f ../hive/testHive.sql

那么您可能在 GenericUDFevaluate() 方法中有以下代码:

Then you may have below code inside a GenericUDF evaluate() method:

@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上测试

The code is tested on hive 1.2

这篇关于如何在 hive udf 中传递 Hive conf 变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆