首页 > 其他 > 详细

Hive清洗emoji及\0

时间:2020-02-02 09:26:21      阅读:93      评论:0      收藏:0      [点我收藏+]

写的UDF

public class FilterEmojiUDF extends UDF {
	public String evaluate(String str) {
		if (str == null || str == "") {
			return null;
		} else {
			StringBuilder sb = new StringBuilder();
			str = str.replace("\0", "");
			byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
			for (int i = 0; i < bytes.length; i++) {
				byte b = bytes[i];
				if (CharUtils.isAscii((char) b)) {
					sb.append(new String(new byte[] { b }));
				} else if ((b & 0xE0) == 0xC0) {
					sb.append(new String(new byte[] { b, bytes[++i] }));
				} else if ((b & 0xF0) == 0xE0) {
					sb.append(new String(new byte[] { b, bytes[++i], bytes[++i] }));
				} else if ((b & 0xF8) == 0xF0) {
					String str1 = new String(new byte[] { b, bytes[++i], bytes[++i], bytes[++i] });
					try {
						sb.append(URLEncoder.encode(str1, CharEncoding.UTF_8));
					} catch (Exception ignore) {

					}
				}
			}
			return sb.toString();
		}
	}
}

  

Hive清洗emoji及\0

原文:https://www.cnblogs.com/hark0623/p/12250999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!