1. 自定义函数
1)Hive 自带了一些函数,比如:max/min 等,但是数量有限,自己可以通过自定义 UDF 来方便的扩展。
2)当 Hive 提供的内置函数无法满足你的业务处理需要时,此时就可以考虑使用用户自定义函数(UDF:user-defined function)。
3)根据用户自定义函数类别分为以下三种:
(1)UDF(User-Defined-Function)一进一出
(2)UDAF(User-Defined Aggregation Function)聚集函数,多进一出类似于:count/max/min
(3)UDTF(User-Defined Table-Generating Functions)一进多出如 lateral view explode()
4)官方文档地址 HivePlugins - Apache Hive - Apache Software Foundation
5)编程步骤:
(1)继承 Hive 提供的类
org.apache.hadoop.hive.ql.udf.generic.GenericUDF
org.apache.hadoop.hive.ql.udf.generic.GenericUDTF;
(2)实现类中的抽象方法
(3)在 hive 的命令行窗口创建函数
添加 jar
add jar linux_jar_path
创建 function
create [temporary] function [dbname.]function_name AS class_name;
(4)在 hive 的命令行窗口删除函数
drop [temporary] function [if exists][dbname.]function_name;
2. 自定义 UDF 函数
0)需求:
自定义一个 UDF 实现计算给定字符串

最低0.47元/天 解锁文章
1642

被折叠的 条评论
为什么被折叠?



