Hive字段中文注释乱码解决办法

时间:2023-03-10 07:14:12
Hive字段中文注释乱码解决办法

Hive字段中文乱码,如执行 show create table xxx 时,表级别注释、字段级别注释发现有乱码现象, 一般都是由hive 元数据库的配置不当造成的。

此时可按如下步骤进行配置调整:

登录hive的元数据库mysql中:

1、设置hive 元数据库字符集

show create database hive;

查看为utf8,需变更为latin1

alter database hive character set latin1;

2、更改如下表字段为字符集编码为 utf8

alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;

alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;

alter table PARTITION_PARAMS  modify column PARAM_VALUE varchar(4000) character set utf8;

alter table PARTITION_KEYS  modify column PKEY_COMMENT varchar(4000) character set utf8;

alter table  INDEX_PARAMS  modify column PARAM_VALUE  varchar(4000) character set utf8;

可以看到,如下语句分别对可能出现中文的字段、表参数、分区设置、及索引参数等字段,调整了字符集编码。