Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器 软件资源

软件开发小程序制作系统集成与运维空间租用硬件开发视频监控技术咨询与支持——联系电话:0311-88999002/88999003

首页 / 操作系统 / Linux / Hive UDF开发

Hive进行UDF开发十分简单,此处所说UDF为Temporary的function,所以需要hive版本在0.4.0以上才可以。
Hive的UDF开发只需要重构UDF类的evaluate函数即可。例:
package com.hrj.hive.udf; import org.apache.Hadoop.hive.ql.exec.UDF; public class helloUDF extends UDF { public String evaluate(String str) { try { return "HelloWorld " + str; } catch (Exception e) { return null; } } } 将该java文件编译成helloudf.jar
hive> add jar helloudf.jar; hive> create temporary function helloworld as "com.hrj.hive.udf.helloUDF"; hive> select helloworld(t.col1) from t limit 10; hive> drop temporary function helloworld; 注: 1. helloworld为临时的函数,所以每次进入hive都需要add jar以及create temporary操作
2. UDF只能实现一进一出的操作,如果需要实现多进一出,则需要实现UDAF