文章来自:http://blog.csdn.net/lili72
背景: 旧版本的hive 在用的过程中,经常出现一些bug,无法解决,比如无法找到表们无法找到分区等。由于并发比较大,常见如下异常:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hive.DELETEME1414791576856' doesn't exist
FAILED: SemanticException [Error 10006]: Line 1:48 Partition not found ''2014-10-26''
FAILED: SemanticException Line 1:99 Exception while processing 'ST_USER_INFO': Unable to fetch table ST_USER_INFO
FAILED: Error in metadata: MetaException(message:java.lang.RuntimeException: commitTransaction was called but openTransactionCalls = 0. This probably indicates that there are unbalanced calls to openTransaction/commitTransaction)
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
(增大hive对mysql的最大连接数,还是效果不明显。SHOW VARIABLES LIKE 'max_conn%';SET GLOBAL max_connections=2000;)
hive 升级
0 下载最新 hive-0.14.0
http://apache.fayea.com/hive/hive-0.14.0/
上传到/home/bigdata/
解压文件 tar -xvf apache-hive-0.14.0-bin.tar.gz
重命名 mv apache-hive-0.14.0-bin hive0140
1 先停止所有对hive的操作,hiveserver 和客户端关闭
2 对mysql数据库 进行备份
mysqldump -h 192.168.119.129 -P 3306 -uroot -p123 hive >hive-20150120-0.9.0.sql
3 修改环境变量
修改环境变量$HIVE_HOME
切换root
vi /etc/profile
source /etc/profile
#export HIVE_HOME=/home/bigdata/hive
export HIVE_HOME=/home/bigdata/hive0140
4 执行升级mysql脚本
cd /home/bigdata/hive0140/scripts/metastore/upgrade/mysql
首先查看该目录的README文件
因为我们已经是0.9.0的版本了,所以只需执行 0.9----0.14
mysql -h 192.168.119.129 -P 3306 -uroot -p123 hive< upgrade-0.9.0-to-0.10.0.mysql.sql
mysql -h 192.168.119.129 -P 3306 -uroot -p123 hive< upgrade-0.10.0-to-0.11.0.mysql.sql
mysql -h 192.168.119.129 -P 3306 -uroot -p123 hive< upgrade-0.11.0-to-0.12.0.mysql.sql
mysql -h 192.168.119.129 -P 3306 -uroot -p123 hive< upgrade-0.12.0-to-0.13.0.mysql.sql
mysql -h 192.168.119.129 -P 3306 -uroot -p123 hive< upgrade-0.13.0-to-0.14.0.mysql.sql
5 将mysql的驱动拷贝到lib目录下。把旧的lib 复制过去
把以前的hive客户端中的jdbcconnect复制到新的hive0140的lib中
cp mysql-connector-java-5.1.23-bin.jar ../../hive0140/lib/
6 将之前旧版本配置好的hive-site.xml,hive-env.xml与hive-log4j.properties放回现在版本的conf下。
修改hive-env.sh配置为新的hive目录
删除配置项
job plan. If the multi group by query has common group by keys, it will be
optimized to generate single M/R job.
creating a HAR. Because this functionality is hard to detect with just version
numbers, this conf var needs to be set manually.
7 升级完成。可以进行hive操作了。再重新开启客户端和server。
8 进入hadoop 用户 执行 命令 hive
查询数据没有问题:
但是当建表的时候发现:报错
FAILED: Error in metadata: javax.jdo.JDODataStoreException: Insert of object "org.apache.hadoop.hive.metastore.model.MStorageDescriptor@139491b" using statement "INSERT INTO `SDS` (`SD_ID`,`IS_COMPRESSED`,`OUTPUT_FORMAT`,`INPUT_FORMAT`,`NUM_BUCKETS`,`SERDE_ID`,`CD_ID`,`LOCATION`) VALUES (?,?,?,?,?,?,?,?)" failed : Field 'IS_STOREDASSUBDIRECTORIES' doesn't have a default value
NestedThrowables:
java.sql.SQLException: Field 'IS_STOREDASSUBDIRECTORIES' doesn't have a default value
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
SDS表的字段IS_STOREDASSUBDIRECTORIES 没有默认值;
修改设置一个默认值为0
先查询以前的值为
select IS_STOREDASSUBDIRECTORIES from SDS limit 10;
alter table SDS alter column IS_STOREDASSUBDIRECTORIES set default 0;
就成功解决插入数据的问题。
二:增加hive的hadoop超级管理权限
1 代码在网上很多:
package com.li72.hive;
import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook;
import org.apache.hadoop.hive.ql.parse.ASTNode;
import org.apache.hadoop.hive.ql.parse.HiveParser;
import org.apache.hadoop.hive.ql.parse.HiveSemanticAnalyzerHookContext;
import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.session.SessionState;
public class HadoopAuthHook extends AbstractSemanticAnalyzerHook {
private static String admin = "hadoop";
@Override
public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context,ASTNode ast) throws SemanticException {
switch (ast.dupNode().getType()){
case HiveParser.TOK_CREATEDATABASE:
case HiveParser.TOK_DROPDATABASE:
case HiveParser.TOK_CREATEROLE:
case HiveParser.TOK_DROPROLE:
case HiveParser.TOK_GRANT:
case HiveParser.TOK_REVOKE:
case HiveParser.TOK_GRANT_ROLE:
case HiveParser.TOK_REVOKE_ROLE:
String userName = null;
if (SessionState.get() != null&& SessionState.get().getAuthenticator() != null) {
userName = SessionState.get().getAuthenticator().getUserName();
}
if (!admin.equalsIgnoreCase(userName)) {
throw new SemanticException(userName+ " can't use ADMIN options, except " + admin + ".");
}
break;
default:
break;
}
return ast;
}
}
2 把代码打成jar包 hive-authhook.jar 上传到hive的lib目录 $HOME_HIVE/lib
3 修改配置文件 配置文件$HOME_HIVE/conf/hive-site.xml
新增:
4 测试:以hadoop账号进入hive,然后建表,是可以的,切换其它账号li72,不能做其它的操作,但是hadoop可以授权给其它账号进行操作。
赋给hadoop所有的权限
GRANT all to user hadoop;
GRANT all on database db1 to user li72