1、查看及修改hive 元数据库字符集
#若元数据库的数据集不为latin1,执行下面语句修改修改
alter database hive character set latin1;
2、切换使用hive元数据库,修改以下表级别的字符集。
修改前:
修改:
#修改表字段注解和表注解
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_KEYS modify column PKEY_COMMENT varchar(4000) character set utf8;
alter table PARTITION_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
#修改索引注解
alter table INDEX_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
修改后:
image.png
3、修改 metastore 的连接 URL
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hdc-data2:3306/hive_remote?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8</value>
</property>
重启hive和客户端
注意:做完此步发现原来创建表的comment还是中文不能正常显示,但新创建的表能正常显示。
4、解决原表的comment中文乱码(待续)
### Eclipse Workspace Patch 1.0
#P hive-0.12.0-jd-svn
Index: ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataFormatUtils.java
===================================================================
--- ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataFormatUtils.java (revision 29)
+++ ql/src/java/org/apache/hadoop/hive/ql/metadata/formatting/MetaDataFormatUtils.java (working copy)
@@ -28,6 +28,8 @@
import java.util.Set;
import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.TableType;
import org.apache.hadoop.hive.metastore.api.FieldSchema;
@@ -47,7 +49,7 @@
*
*/
public final class MetaDataFormatUtils {
-
+ private static final Log LOG = LogFactory.getLog("org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatUtils");
public static final String FIELD_DELIM = "\t";
public static final String LINE_DELIM = "\n";
@@ -262,10 +264,20 @@
private static void displayAllParameters(Map<String, String> params, StringBuilder tableInfo) {
List<String> keys = new ArrayList<String>(params.keySet());
+ String value = null;
Collections.sort(keys);
for (String key : keys) {
tableInfo.append(FIELD_DELIM); // Ensures all params are indented.
- formatOutput(key, StringEscapeUtils.escapeJava(params.get(key)), tableInfo);
+ value = params.get(key);
+ LOG.info(">>lvxin displayAllParameters:key="+key+";params.get(key)="+params.get(key));
+ if("comment".equals(key)&& null!=value && value.getBytes().length!=key.length())
+ {
+ formatOutput(key, value, tableInfo);
+ }
+ else
+ {
+ formatOutput(key, StringEscapeUtils.escapeJava(value), tableInfo);
+ }
}
}
网友评论