使用hive导入数据到分区中报错如下:
Failed with exception MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)
org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)
.......
Caused by: MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)
at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.reconnect(HiveMetaStoreClient.java:307)
at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.invoke(RetryingMetaStoreClient.java:98)
at com.sun.proxy.$Proxy9.appendPartition(Unknown Source)
at org.apache.hadoop.hive.ql.metadata.Hive.getPartition(Hive.java:1833)
... 22 more
ERROR : FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask
在网上找了许多,发现一个解决办法,应该是hive,配置文件中取的元数据库名称有问题导致的,注:楼主使用的是mysql作为元数据存储
楼主最开始的hive-site.xml文件,如下:
楼主将配置文件中的,元数据库名称改为metastore,后重启hive,(注意重启后,Hive会回到初始化状态,(因为还了元数据库,之前的记录也就没有了))
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop002:3306/metastore?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
<!-- 如果 mysql 和 hive 在同一个服务器节点,那么请更改 hadoop02 为 localhost -->
</property>
然后,在mysql元数据库上执行一下:否则建表可能会报错
alter database metastore character set latin1;
执行的一下hql如下:后面就成功了
--创建数据库
create database myhive2;
--使用数据库
use myhive2 ;
--创建分区表
create TABLE student1(id int ,name string,age int,sex string) partitioned BY (
grade string)
row format delimited
fields terminated by ',';
--从hdfs上导入数据到表中
LOAD DATA INPATH '/test/student.txt' INTO TABLE student1 PARTITION(grade = '3');
--从本地导入数据到分区表好着呢个
load data local inpath "/usr/hive/student.txt" into table student1 PARTITION(grade = '1');
注意:如果配置文件中,。没有指定数据仓库位置,建表的默认路径如下:
注意:对于从hdfs中导入数据到分区表中(或者一般表),hdfs上原先位置的的文件会被移动到表的目录下。
注意如下:是建立外部表,需要指定locatio
--创建外部表,需要指定路径
create EXTERNAL TABLE student2 (id int ,name string,age int,sex string) partitioned BY (
grade string)
row format delimited
fields terminated by ','location '/student2';
--从本地数据导到外部表中(分区)
load data local inpath "/usr/hive/student.txt" into table student2 PARTITION(grade = '1');
--从hdfs导数到外部表(分区)中
LOAD DATA INPATH '/test/student.txt' INTO TABLE student2 PARTITION(grade = '3');
导入数据到分区中的文件目录结构如下:
--从hdfs导数到外部表(分区)中,指定一个文件夹
LOAD DATA INPATH '/test' INTO TABLE student2 PARTITION(grade = '2');
导入数据时,也可以指定文件夹,就会将该文件夹下的所有文件移动到分区中
补充说明,导数据到分区中的两种语句,及区别(数据是否移动到建表所在目录下)
--数据没有移动到表的路径下
ALTER TABLE ods_app_log ADD PARTITION (os = 'android') location '/afterclean/android';
--数据移动到表的路径下
LOAD DATA INPATH '/afterclean/ios' INTO TABLE ods_app_log PARTITION(os = 'ios');
补充说明:
楼主发现,将元数据库名称改为metastore后,hive查询速度可各种执行速度,飙升了许多,不知道,是不是因为省了读取配置文件的世界,默认配置会好很多。
下面是hive的配置文件,hive-site.xml
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop002:3306/metastore?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
<!-- 如果 mysql 和 hive 在同一个服务器节点,那么请更改 hadoop02 为 localhost -->
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>password to use against metastore database</description>
</property>
<!--
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/afterclean</value>
<description>hive default warehouse, if nessecory, change it</description>
</property> -->
</configuration>