hive UDF 过滤字符串中的中英文标点符号
来源:互联网 发布:游戏破解编程 编辑:程序博客网 时间:2024/05/18 20:33
使用hive 过程中 需要做一些UDF的开发,简单贴一个UDF 是用来去除字符串中的所有中英文符号
本人JAVA 菜鸟 代码可能不好看勿喷啊。仅供参考
package com.fccs.utils;import java.text.ParseException;import org.apache.hadoop.hive.ql.exec.UDF;/*** * 本类是用于字符串替换支持正则表达 * @author yqj@fccs.com * @date 2015-5-28 * @version 1.0 * */public class F_str_replace extends UDF{public String evaluate(String str,String ...args) {if(str != null){str = str.trim();}if(str == null || "".equals(str)){return "null";}return get_str_replace( str,args);}/** * 传入一个字符串,把所有符合条件的字符串和空字符转换为“null”,不符合条件的就返回原字符串 * 比如:get_str_replace("金成·江南春城 (·竹海水韵)") * 转换后:"金成江南春城竹海水韵" * @param subject * @param args 多参数 args[0] 要替换成的字符串, args[1] 正则表达式 * @use:get_str_replace(subject,replacement,pattern) * @return result */private static String get_str_replace(String subject,String...args){ String text = "null";if(subject != null){subject = subject.trim();}if(subject == null || "".equals(subject)){return "null";} if(args.length==0){text = subject.replaceAll( "\\p{Punct}","" ); text = text.replaceAll("\\pP" , ""); text = text.replaceAll("\\p{P}" ,""); text = text.replaceAll( "[\\p{P}+~$`^=|<>~`$^+=|<>¥×]" , ""); }else if (args.length==1){String replacement = args[0].length()>0?args[0]:"";text = subject.replaceAll( "\\p{Punct}",replacement ); text = text.replaceAll("\\pP" , replacement); text = text.replaceAll("\\p{P}" ,replacement); text = text.replaceAll( "[\\p{P}+~$`^=|<>~`$^+=|<>¥×]" , replacement); }else{String pattern = args[1];String replacement = args[0] ; text = subject.replaceAll( pattern,replacement); }text = text.replaceAll("\\s+", ""); //过滤多余空格return text; }}
0 0
- hive UDF 过滤字符串中的中英文标点符号
- 将字符串中的标点符号过滤掉
- Hive UDF整理 字符串函数
- php实现过滤中英文标点符号[gbk编码环境]
- PHP截取中英文及标点符号混合的字符串函数
- hive UDF实现一个字符串解码函数
- hive中的udf时间函数用法
- hive中的udf时间函数用法
- hive中的udf时间函数用法
- hive中的udf时间函数用法
- hive UDF 提取文本中的地名
- hive UDF 提取文本中的国家名
- Hive中的UDF及自定义函数示例
- Hive中的用户自定义函数UDF
- hive udf
- hive-udf
- hive UDF
- hive UDF
- uva 585(字符串)
- MySQL被慢sql hang住了,用shell脚本快速清除不断增长的慢sql的办法
- 如何快速的修改参考文献
- android Service重启问题,结合AlarmManager实现定时任务
- 自定义控件-UIControl
- hive UDF 过滤字符串中的中英文标点符号
- SQL方法~获取给定时间所在周一至周日的日期范围
- 计算MySQL的内存峰值公式
- NYOJ 76 超级台阶 DP
- Skype for Business Server 2015操作系统要求
- innobackupex-1.5.1: Too many command line arguments
- java时间格式转化(毫秒 to 00:00)
- Excel 培训笔记
- 数据类型中补充