Hive的UDF开发只需要重构UDF类的evaluate函数即可。例:
public String evaluate(String key, String data) {
// System.out.println("print 1234!");
try {
if (null != key && null != data) {
return decrypt(key, data);
} else {
return null;
}
} catch (Exception e) {
return null;
}
}
//解密
public static String decrypt(String key, String hexString) {
<span style="white-space:pre"> </span>...
<span style="white-space:pre"> </span>}
}
//创建临时函数环境
hive> add jar hdfs:///udf/UDF_decrypt.jar;
hive> create temporary function my_decrypt as 'com.wy.hive.udf.DecryptUDF';
hive> select my_decrypt("www.xxxxxx.com.cn",'8F0410BDDD1C95AB0E7F742CA81A1B8C135606C96FAA3D9A81F9AB1938E216A2BF2ACF07C16E4599533D7A36DD55224D'),* from dm.FCT_SAME_CARD_MERCHANT_NO_DAY limit 1;
期间遇到的错误:
FAILED: SemanticException [Error 10014]: Line 1:7 Wrong arguments '"3FDDD869106061B53B571B8124CD966F"': No matching method for class com.wy.hive.udf.DecryptUDF with (string, string). Possible choices
匹配不到该类相关的方法,后来排查,原来是在重构evaluate方法时,把public修饰符写成了私有的private,所以找不到咯!