Hive 3 - UDF函数

作者: No_七 | 来源:发表于2019-10-25 14:32 被阅读0次

Eclipse编写自定义UDF函数步骤

1、配置 pom

添加两个dependency

<dependency>
     <groupId>org.apache.hive</groupId>
     <artifactId>hive-exec</artifactId>
     <version>1.2.2</version>
</dependency>

<dependency>
     <groupId>org.apache.hive</groupId>
     <artifactId>hive-jdbc</artifactId>
     <version>1.2.2</version>
</dependency>
image.png

2、下载 hive-site.xml,放到 bin目录下,刷新maven项目

工程目录 右键 -> Maven -> Update Project

image.png

3、编写功能代码

image.png

4、打成Jar包,并上传到服务器(略)

image.png image.png

5、在Hive中关联Jar,并创建临时函数 (3种方法)

5.1 本地临时函数

add jar local_path;

hive (db02)> add jar /opt/datas/udf_time.jar;
image.png

create temporary function 函数名 as ‘包名.类名';

hive (db02)> create temporary function mytime as 'com.bigdata.hive.HiveUdfTime';
image.png
5.2 HDFS临时函数

或者可以直接上传到HDFS上,

hive (db02)> dfs -put /opt/datas/udf_time.jar /;
image.png

create temporary function 函数名 as '包名.类名' using jar 'hdfs_path' ;

hive (db02)> create temporary function mytime1 as 'com.bigdata.hive.HiveUdfTime' using jar 'hdfs://hadoop06:8020/udf_time.jar';
image.png
5.3 永久函数

将Hive的jar添加到Hive的环境变量,并且编译Hive的源码

6、查看自定义函数

hive (db02)> show functions;

7、使用自定义函数

hive (db02)> select time_local,mytime1(time_local) newtimes from apachelog3;

相关文章

网友评论

    本文标题:Hive 3 - UDF函数

    本文链接:https://www.haomeiwen.com/subject/tjvsvctx.html