问题:hive表的字段数据中有NUL数据,导致无法将hive数据导出
解决:使用regexp_replace(CFWH, '\x00', ''),x00可以匹配到NUL
方法:
在数据从ods层进入dwd层时进行数据治理
// 在hive中的查询语句
select sxh, regexp_replace(replace(CFWH, decode(unhex(hex(127)), "US-ASCII"), ""), "\\x00", "")
from ods_xscfjl where sxh in (1020,1107);
# 脚本中的调用语句
dwd_cfjl="
set hive.input.format=org.apache.hadoop.hive.ql.io.HiveInputFormat;
insert overwrite table ${APP}.dwd_cfjl partition(dt='$do_date')
select
SXH,
XH,
regexp_replace(replace(CFWH, decode(unhex(hex(127)), 'US-ASCII'), ''), '\\\\x00', '') CFWH,
CJSJ,
CJZ
from ${APP}.ods_xscfjl
where dt='$do_date';
"
注:'x00' 需要加一个转义符,正则中写'\x00',decode(unhex(hex(127)), 'US-ASCII')是过滤字段中的DEL字符
参考:
https://www.freesion.com/article/85491519620/