执行insert overwrite table 没有正确的返回numRows和rawDataSize;结果类似如下 [numFiles=1, numRows=0, totalSize=59, rawDataSize=0]
在hive stats mysql 数据库也没有任何相关的stats插入进来。
先定位问题是hive stats出现问题,由于console打印出来的信息过少,无法精确定位问题;因此设置
hive --hiveconf hive.root.logger=INFO,console ;将详细日志打印出来,发现以下信息:
[Error 30001]: StatsPublisher cannot be initialized. There was a error in the initialization
of StatsPublisher, and retrying might help. If you dont want the query to fail because accurate
statistics could not be collected, set hive.stats.reliable=false Specified key was too long; max key length is 767 bytes
这个问题比较简单,是由于hive1.1.0,ID column长度默认为4000;而且设置ID为主键,导致报错
org.apache.hadoop.hive.ql.stats.jdbc.JDBCStatsSetupConstants
// MySQL - 65535, SQL Server - 8000, Oracle - 4000, Derby - 32762, Postgres - large.
public static final int ID_COLUMN_VARCHAR_SIZE = 4000;
org.apache.hadoop.hive.ql.stats.jdbc.JDBCStatsPublisher:public boolean init(Configuration hconf)
if (colSize < JDBCStatsSetupConstants.ID_COLUMN_VARCHAR_SIZE) {
String alterTable = JDBCStatsUtils.getAlterIdColumn();
stmt.executeUpdate(alterTable);
} 从这个代码知道,如果表的ID column size小于4000,会被自动改为4000;因此只有修改源码将4000->255(mysql采用utf8编码,一个utf8占用3个字节,因此255*3=765