hive 永久udf函数

来源:互联网 发布:富网店淘宝课程怎么样 编辑:程序博客网 时间:2024/04/28 16:54
开发环境: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

0 0