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

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

问题描述

下面是一个代码片段。



<$ p

 $ b $ p 

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

下面是hive UDF调用。

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

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

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

解决方案

您可以使用GenericUDF。它有一个将MapredContext作为参数的方法配置。因此,您需要在GenericUDF中指定一个配置方法,如:

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


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?

解决方案

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

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

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