关于Hive的中文注释以及hwi查询中文结果的问题

来源:互联网 发布:js防止表单二次提交 编辑:程序博客网 时间:2024/04/27 23:46

1.Hive中文注释

当在hive中使用create table t1(c1 string comment '列1');创建表t1后,若用describe t1;显示表结构,则注释部分‘列1’显示为‘?1’

因此需要在MySQL数据库中对hive数据库的表进行编码设置,前文在配置环境部分已经对hive-site.xml中与MySQL连接的编码设置为UTF-8,正常的数据部分的中文在命令行下是可以显示的,此处仅叙述对MySQL中表的设置

使用mysql -u root -p进入MySQL

show databases;显示所有数据库

use hive;进入hive的默认数据库

show tables;查看所有表

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;修改表注释字符集

在hive中删除t1表之后再重新创建即可显示中文注释

其他相关设置可参考解决各个hive版本中文注释不能正确显示的问题  

关于MySQL的命令查看Mysql命令 

2.hwi查询结果显示中文

 在hwi创建会话查询数据,结果中文部分无法显示


数据文件在导入hive前已经转换成UTF-8编码,而且命令行可以正常显示,因此可能是hwi的web页面设置时没有对编码做相关设置,查看url得知view_result.jsp为当前的web文件,于是在~/hive/lib下找到打包好的hive-hwi-2.1.0.war,里面是hwi的web文件,找到view_result.jsp,在文件头部指定编码格式

<%--   Licensed to the Apache Software Foundation (ASF) under one or more   contributor license agreements.  See the NOTICE file distributed with   this work for additional information regarding copyright ownership.   The ASF licenses this file to You under the Apache License, Version 2.0   (the "License"); you may not use this file except in compliance with   the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.--%><%@ page contentType="text/html;charset=UTF-8"%><%@page errorPage="error_page.jsp" %><%@ page import="org.apache.hadoop.hive.hwi.*,java.io.*" %><% HWIAuth auth = (HWIAuth) session.getAttribute("auth"); %><% HWISessionManager hs = (HWISessionManager) application.getAttribute("hs"); %><% if (auth==null) { %><jsp:forward page="/authorize.jsp" /><% } %><% String sessionName=request.getParameter("sessionName"); %><% HWISessionItem sess = hs.findSessionItemByName(auth,sessionName);%><% int start=0;    if (request.getParameter("start")!=null){     start = Integer.parseInt( request.getParameter("start") );   }%><% int bsize=1024;    if (request.getParameter("bsize")!=null){     bsize = Integer.parseInt( request.getParameter("bsize") );   }%>
第17行为编码格式,保存文件并重新启动hwi后查询结果显示为中文



0 0
原创粉丝点击