如何在配置单元中添加永久功能? [英] how to add a permanent function in hive?

查看:127
本文介绍了如何在配置单元中添加永久功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是问题:如果我在这样的配置单元中声明一个临时函数

  add jar /home/taobao/oplog/hivescript/my_udf.jar; 
以'com.my.udf.GetContentValue'创建临时函数getContentValue;

对于函数 getContentValue 在此配置单元会话中。但我想要的是不必添加jar以及每次启动蜂巢会话时创建临时函数。也就是说,使功能永久



有没有解决这个问题的方法?

解决方案

0.13.0( HIVE-6047 ),您可以通过以下方式使UDF永久化:

  CREATE FUNCTION [db_name。] function_name AS class_name [使用JAR | FILE | ARCHIVE'file_uri'[,JAR | FILE | ARCHIVE'file_uri ']] 

您的UDF示例:

  CREATE FUNCTION getContentValue AS'com.my.udf.GetContentValue'USING JAR'/home/taobao/oplog/hivescript/my_udf.jar'; 

更多信息请查看 Hive Data Definition Language ,引用它: p>这个语句允许你创建一个由class_name实现的函数。可以使用USING子句指定需要添加到环境中的Jars,文件或存档;当该函数首次被Hive会话引用时,这些资源将被添加到环境中,就好像ADD JAR / FILE已经发布一样。如果Hive不处于本地模式,那么资源位置必须是非本地URI,例如HDFS位置。



该函数将被添加到指定的数据库中,或在创建函数时将其添加到当前数据库。该函数可以通过完全限定函数名称(db_name.funciton_name)来引用,或者如果该函数位于当前数据库中,则可以无限制地引用该函数。



Here is the problem: If I declare a temporary function in hive like this:

add jar /home/taobao/oplog/hivescript/my_udf.jar;
create temporary function getContentValue as 'com.my.udf.GetContentValue';

It'll works fine with function getContentValue in this hive session. But what I want is not having to add jar as well as create temporary function every time I start a hive session. That is to say, make the function permanent.

Is there any solutions to this problem?

解决方案

As of 0.13.0 (HIVE-6047) you can make UDFs permanent through:

CREATE FUNCTION [db_name.]function_name AS class_name [USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 'file_uri'] ]

An example for your UDF:

CREATE FUNCTION getContentValue AS 'com.my.udf.GetContentValue' USING JAR '/home/taobao/oplog/hivescript/my_udf.jar';

For more info check Hive Data Definition Language, quoting it:

This statement lets you create a function that is implemented by the class_name. Jars, files, or archives which need to be added to the environment can be specified with the USING clause; when the function is referenced for the first time by a Hive session, these resources will be added to the environment as if ADD JAR/FILE had been issued. If Hive is not in local mode, then the resource location must be a non-local URI such as an HDFS location.

The function will be added to the database specified, or to the current database at the time that the function was created. The function can be referenced by fully qualifying the function name (db_name.funciton_name), or can be referenced without qualification if the function is in the current database.

这篇关于如何在配置单元中添加永久功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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