1. impala过滤中文
select
city
from tablename
where ds >= %start_date%
and ds <= %end_date%
and regexp_like(city,'^[\u4e00-\u9fa5]*$')
字符 | 说明 |
---|---|
\u4e00-\u9fa5 | 汉字的unicode范围 |
\u0030-\u0039 | 数字的unicode范围 |
\u0041-\u005a | 大写字母unicode范围 |
\u0061-\u007a | 小写字母unicode范围 |
注意:
数字 和 字母可以不使用上面提供的unicode码来分辨, 而使用下面的方式 (其实都是一样的):
^[\u4e00-\u9fa5_a-zA-Z0-9]+$
2. hive过滤中文
case when current_city regexp '^[\\u4e00-\\u9fa5]*$' then current_city else 'unknown' end as current_city
3. 过滤城市脏数据
今天碰到有个问题, 要过滤掉城市中脏数据, 保留中文城市数据. 但是数据已经经过了编码, 使用上面的方式会存在问题, 因此这里产生了专门针对城市的:
and city regexp '^(.*)[市|州|区|盟|县|国|湾]$'
特别的好用~
另外记录下Excel怎么获取最后一个字符:
=RIGHT(A2,1)
4. Hive进行Base64加密解密
select
base64( cast( '北京市' as binary ) ) --加密
,unbase( 'xxx' ) --解密
from tablename
5. ClickHouse进行Base64加密解密
select
base64Encode( '北京市' ) --ClickHouse加密
,base64Decode( 'xxx' ) --ClickHouse解密
from tablename
6. Hive编码解码
encode(string src, string charset)
参数一:要编码的字符串
参数二:编码方式 (支持US-ASCII,ISO-8859-1, UTF-8,UTF-16BE,UTF-16LE, UTF- 16)
decode(binary bin, string charset)
参数一:要解码的二进制数组
参数二:解码方式(支持US-ASCII,ISO-8859-1, UTF-8,UTF-16BE,UTF-16LE, UTF- 16)
上面的解码方式不支持GBK
reflect(class, method[, arg1[, arg2…]])
通过使用反射匹配参数签名来调用Java方法。
select
reflect('java.net.URLDecoder', 'decode',event_value, "GBK")
from table