能够对输入数据进行非空判断、手机号位数判断能够实现校验手机号格式,把满足规则的进行****处理对于不符合手机号规则的数据直接返回,不处理
Maven必须配置执行步骤org.apache.hive hive-exec3.1.2 org.apache.hadoop hadoop-common3.1.4
第一步:自定义代码编写
package cn.test.hive.udf;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hive.ql.exec.UDF;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EncryptPhoneNumber extends UDF {
public String evaluate(String phoNum){
String encryptPhonum = null;
//手机号不为空 并且为11位
if (StringUtils.isNotEmpty(phoNum) && phoNum.trim().length() == 11 ) {
//判断数据是否满足中国大陆手机号码规范
String regex = "^(1[3-9]\d{9}$)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(phoNum);
if (m.matches()) {//进入这里都是符合手机号规则的
//使用正则替换 返回加密后数据
encryptPhonum = phoNum.trim().replaceAll("(\d{3})\d{4}(\d{4})","$1****$2");
}else{
//不符合手机号规则 数据直接原封不动返回
encryptPhonum = phoNum;
}
}else{
//不符合11位 数据直接原封不动返回
encryptPhonum = phoNum;
}
return encryptPhoNum;
}
}
第二步:IDEA中使用集成的Maven插件进行打包
第三步:Jar包上传HS2本地服务器
第四步:将Jar添加至Hive Classpath中
第五步:注册临时函数
create temporary function 函数名 as 'UDF类全路径';
第六步:使用



