Hive问题总结

1.java.sql.SQLException: null,  message from server: "Host '***' is not allowed to connect to this *** server"

第一个***是你的主机名(linux),后面的***表示你所连接的数据库服务器名称,可能是MySQL.

这个错误的意思是主机***没有访问***数据库服务器的权限

所以,这里只要在你安装数据库的机子上,进入mysql的命令行,赋予权限即可:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '这里写你的mysql密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;



2.Caused by: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql))

很显然这是因为作为metastore的数据库没有初始化,错误中已经告诉我们怎么解决,只要一条命令:

./schematool -initSchema -dbType mysql(这里按照你自己用的数据库来初始化,可以是derby,我用的mysql)

3.hive运行时出错:例如执行drop table tablename;失败
SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)
语义异常:这是因为字符集造成的

在mysql的命令行窗口执行:alter database hive character set latin1; 其中hive是我的数据库名字,这里要按照你自己的来写。


4. hive 从非分区表插入数据到分区表时出错:

Cannot insert into target table because column number/types are different ''分区名'': Table insclause-0 has 2 columns, but query has 3 columns.

首先解释一下这个错误:因为hive的分区列是作为元信息存放在mysql中的,他们并不在数据文件中,相反他们以子目录的名字被使用,因此你的分区表实际含有的数据列,注意是数据列是不包含分区列的,所以在你向分区表插入数据时,不能插入分区列;


举个简单的例子:体育课上站队时,老师经常让男生、女生各站一队,你觉得有必要再给他们每一个人加上一个性别的标签吗?


下面是stackoverflow上大神关于这个问题的解释:

 In Hive the partitioning "columns" are managed as metadata >> they are not included in the data files, instead they are used as sub-directory names. So your partitioned table has just 2 real columns, and you must feed just 2 columns with your SELECT.

比如你的非分区表non_part的内容如下:

id	name	sex
1	tom 	M
2	mary	F

假如你的分区表part是以sex来分区的,当你想把以上非分区表中的数据插入到分区表中:

你应该:insert into table part partition(sex='M') select id,name from non_part where sex='M';(对,你要插入的就是两列,分区列不作为数据保存在数据表中)

而不是insert into table part partition(sex='M') select  *  from non_part where sex='M';


另外需要注意的地方:

1.从非分区表插入数据到分区表时hive会将HiveQL转换为MR来执行的,官方提示Hive-on-MR在将来可能不再被支持;

2.只要是向分区表内装数据,无论是load还是insert都要在表名后指明分区名;而且load时,会将你要load的文件内的所有内容放在指定的分区下;




  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值