How to pass Hive conf variable in hive udf?

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I want to pass hive conf variable to hive UDF.

below is a code snippet.

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

Below is hive UDF call.

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

In udf I am getting value of testArg as null.

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

回答1:

I think this is duplicate How to set variables in HIVE scripts

You need to say ${hiveconf:testArg}



回答2:

You can use GenericUDF. It has a method configure which takes MapredContext as a parameter. So, you need to specify a configure method in GenericUDF, like :

public void configure(MapredContext context){  yourVar = context.getJobConf().get("hive_variable"); } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!