暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

0087.C hue中hive创建含中文注释的表报错'ascii' codec can't decode byte 0xe5

rundba 2021-08-28
1837

0.ENV

CentOS7.6;

CDP7.1.4。

1. 问题现象

1) 通过hue,在hive创建含中文注释时报错

类似"'ascii' codec can't decode byte 0xe5 in position %: ordinal not in range(128)"。

创建含中文注释的表报错:

    create table code_set_test(id int comment 'number',content string comment '备注',country_name string comment '国家名称');

    'ascii' codec can't decode byte 0xe5 in position 75: ordinal not in range(128)

    2) 但使用beeline创建含中文注释的表成功

      0: jdbc:hive2://cdp-vip.rundba.com:1001> create table code_set_test(id int comment 'number',content string comment '备注',country_name string comment '国家名称');
      0: jdbc:hive2://cdp-vip.rundba.com:1001> show tables;
      +----------------+
      | tab_name |
      +----------------+
      | code_set_test |
      | t1 |
      | t2 |
      +----------------+

      2. 问题原因

      在CDP7.1.4中,Hue使用兼容Python 2.7.x的语法,默认字符集对中文不支持。

      3. 解决方法

      通过在sitecustomize.py文件中设置UTF8字符集,在python每次启动后都会先调用该文件信息,从而支持中文。

      1) 查询hue

      CM--Hue--实例,查看所有Hue Server主机名称。

      2) 新增sitecustomize.py文件

      登陆所有Hue Server服务器,在/usr/lib/python2.7/site-packages目录下新增sitecustomize.py文件。

        vi usr/lib/python2.7/site-packages/sitecustomize.py      #添加以下内容
        # encoding=utf8
        import sys
        reload(sys)
        sys.setdefaultencoding('utf8')

        3) 重启Hue

        CM--Hue--重启。

        CM页面,如果有过期服务,则重启过期服务。

        4) 验证

        再次通过hue,创建含中文注释的表,成功。

        4. 回退方案

        删除新增的sitecustomize.py文件,重启hue。

        5. 小结

        通过hue,在hive创建含中文注释时,会有报错类似"'ascii' codec can't decode byte 0xe5 in position %: ordinal not in range(128)",相同的语句通过beeline创建成功。在CDP7.1.4中,Hue使用兼容Python 2.7.x的语法,默认字符集对中文不支持。通过在sitecustomize.py文件中设置UTF8字符集,在python每次启动后都会先调用该文件信息,从而支持中文。


        文章转载自rundba,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

        评论