hive UDF实现一个字符串解码函数
来源:互联网 发布:易语言获取网页源码 编辑:程序博客网 时间:2024/06/06 03:26
其实hive的udf 是比较容易实现的,只需要继承UDF,实现其evaluate()方法,代码如下。
@Description(name = "decoder_url", value = "_FUNC_(url [,code][,count]) - decoder a URL from a String for count times using code as encoding scheme ", extended = "" + "if count is not given ,the url will be decoderd for 2 time," + "if code is not given ,GBK is used")public class UDFDecoderUrl extends UDF { private String url = null; private int times = 2; private String code = "GBK"; public UDFDecoderUrl() { } public String evaluate(String urlStr, String srcCode, int count) { if (urlStr == null) { return null; } if (count <= 0) { return urlStr; } if (srcCode != null) { code = srcCode; } url = urlStr; times = count; for (int i = 0; i < times; i++) { url = decoder(url, code); } return url; } public String evaluate(String urlStr, String srcCode) { if (urlStr == null) { return null; } url = urlStr; code = srcCode; return evaluate(url, code,times); } public String evaluate(String urlStr, int count) { if (urlStr == null) { return null; } if (count <= 0) { return urlStr; } url = urlStr; times = count; return evaluate(url, code,times); } public String evaluate(String urlStr) { if (urlStr == null) { return null; } url = urlStr; return evaluate(url, code,times); } private String decoder(String urlStr, String code) { if (urlStr == null || code == null) { return null; } try { urlStr = URLDecoder.decode(urlStr, code); } catch (Exception e) { return null; } return urlStr; }}
在类中org.apache.hadoop.hive.ql.exec.FunctionRegistry中添加
registerUDF("decoder_url", UDFDecoderUrl.class, false);
编译hive ,或者通过配置文件方式,让其读取,以后新加的函数配置到配置文件中一劳永逸。
上面的类UDFDecoderUrl需要打成jar包加载到hive中,需要再hive-site.xml配置如下加载jar包
<property>
<name>hive.aux.jars.path</name>
<value>file:///opt/hive/sohu/hive-udf-0.0.1.jar</value>
<description>These JAR file are available to all users for all jobs</description>
</property>
- hive UDF实现一个字符串解码函数
- Hive UDF整理 字符串函数
- Hive UDF实现函数MD5
- 【Hive自定义UDF函数】 与 【hive字符串函数】
- Hive UDF实现分析函数row_number
- Hive UDF实现分析函数row_number
- 开发hive UDF函数
- HIVE 自定义函数 UDF
- HIVE UDF函数(一)
- hive的UDF 函数
- hive的UDF 函数
- HIVE UDF函数使用
- 开发hive UDF函数
- Hive UDF函数
- hive 永久udf函数
- Hive自定义函数-UDF
- hive UDF函数开发
- hive 永久udf函数
- 搭建云计算环境:CentOS+XEN+Eucalyptus
- Base64解密
- MFC的数组类:CArray,CByteArray,CWordArray,CDWordArray
- C++ strptime实现
- linux C经典面试题五
- hive UDF实现一个字符串解码函数
- poj 1088 滑雪问题
- hdu 1272 小希的迷宫
- google地图改版后 不使用帐号获取 key的方法 {已经 过时}
- Linux 多线程函数解析
- Android无法访问本地服务器(localhost)的解决方案
- 本次OA系统设计经验,休假前的总结
- Android 在代码中设置ProgressBar的style
- 关于弹出框与源页面交互的一点小收获(基于wabacus开发框架)