地址:https://git.100tal.com/peiyou_bigdata/hive-udf.git
java文件放置路径:hive-udf/src/main/java/com/bigdata/udf
1、编写udf代码(string转long型)
package com.bigdata.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
public class MD5ToLong extends UDF{
public static Long evaluate(String orgStr) {
if (orgStr == null || "".equals(orgStr)){
throw new RuntimeException("入参异常"+orgStr);
}
byte [] source =orgStr.getBytes();
int l = orgStr.length();
int i = 0;
int seed = 131;
Long hash= 0L;
while (i
2、本地测试代码逻辑无问题后打包
第三步
1、jar包上传
如果新开发udf有引入系统没有的依赖包时,上传有依赖的jar包,没有引入系统没有的依赖包时可上传没有依赖的jar包
jar包上传路径:/hive/udf/peiyou/ (可通过T-data或跳板机上传)
2、创建udf函数
create function py_func.md5to_long as 'com.bigdata.udf.MD5ToLong' using jar 'hdfs://tal-bx-cluster/hive/udf/peiyou/hiveUdf-1.0-md5to_long-v0.1-SNAPSHOT-jar-with-dependencies.jar';
reload function
select py_func.md5to_long('dfbsdlvbjsdfhg')
3、删除自定义udf:
先删除函数:drop function [if exists] py_func.md5to_long
再删除jar包:hadoop dfs -rm hdfs://tal-bx-cluster/hive/udf/peiyou/hiveUdf-1



