您的位置:首页 > 其它

hive 永久udf函数

2015-11-25 16:54 411 查看
开发环境:cdh5.4.8,hive1.1

最近需要开发一些永久的函数供业务使用,在hive的早期版本中,只能添加临时函数或者修改一些源代码来添加永久函数,后面找到了下面的文档来创建永久函数

Permanent Functions

In Hive 0.13 or later, functions can be registered to the metastore, so they can be referenced in a query without having to create a temporary function each session.

Create Function

CREATE FUNCTION [db_name.]function_name AS class_name

  [USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 'file_uri'] ];

这里需要先把开发好的jar包上传到hdfs上

hadoop fs -put xx.jar /user/hive/udfs/

然后创建函数:

CREATE FUNCTION time_diff_bl AS 'com.bl.bigdata.udf.DateDiffer' using jar 'hdfs://nameservice1:8020/user/hive/udf/bl_udfs-0.0.1-SNAPSHOT.jar';

这样就可以使用了。

2.hue中udf的使用
在hive界面的左边中选择settings->file resources(add)->选择hdfs上的jar->execute 就可以用了

参考:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateFunction
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: