
如何解决hive表中的乱码现象网上有不少解决方案,那么如何查询是否存在乱码呢?
一般来说,自己查询的时候查一下前10行就能查看是否有数据出现乱码现象。
比较合理的方法是将数据字段按照升序和降序分别做一次排序查看是否有乱码现象,这里提供一种解决思路,下面是写好的shell脚本。
#创建文件2.out
echo " " > 2.out
#对文件1.out进行循环,1.out是提前准备好的文件。
for line in `cat 1.out`
#开始循环
do
#输出sql语句 升序排序
echo select ${line} from edwd.DWD_D_PR_SAI_MEMBER_INST order by ${line} ASC >> 2.out
#执行sql语句 进行升序排序并选择前10条
hive -e "select ${line} from edwd.DWD_D_PR_SAI_MEMBER_INST where acct_month=202111 and day_id = 16 order by ${line} ASC LIMIT 10" >> 2.out
#输出sql语句 降序排序
echo select ${line} from edwd.DWD_D_PR_SAI_MEMBER_INST order by ${line} DESC >> 2.out
#执行sql语句 进行降序排序并选择前10条
hive -e "select ${line} from edwd.DWD_D_PR_SAI_MEMBER_INST where acct_month=202111 and day_id = 16 order by ${line} DESC LIMIT 10" >> 2.out
#输出
echo "***************************************************" >> 2.out
#结束循环
done