2017-07-27 107 views
1

首先我创建一个蜂巢分区表:插入到蜂巢分区表错误

hive> create table partition_table 
    > (sid int ,sname string ,age int)    
    > partitioned by (sex string)  
    > row format delimited fields terminated by','; 
OK 
Time taken: 1.232 seconds 

下表说明在下面给出:

hive> desc partition_table; 
    OK 
    sid      int           
    sname     string          
    age      int           
    sex      string          

# Partition Information  
# col_name    data_type    comment    

sex      string          
Time taken: 0.34 seconds, Fetched: 9 row(s) 

,然后我插入一些数据到这个表,但它不没有工作。

hive> insert into table partition_table partition(sex='M')select sno ,sname ,age from student1 where sex ='M'; 
FAILED: SemanticException [Error 10006]: Line 1:44 Partition not found ''M'' 

为了避免这一点,我写了下面的命令,然后执行我的插入命令,即使在当时我反复得到同样的错误。

set exec.dynamic.partition=true;                   
set exec.dynamic.partition.mode=nonstrict; 

请指导我。在此先感谢

+0

你可以添加'select sno,sname,来自student1的年龄,其中sex ='M''输出到问题。查询没有问题。 – syadav

+0

当然..分区列是否必须是英文 –

回答

2

装载前添加分区:

ALTER TABLE partition_table ADD PARTITION(sex= 'M'); 
insert into table partition_table partition(sex='M') select sno ,sname ,age from student1 where sex ='M'; 

或尝试动态分区:

set hive.exec.dynamic.partition=true; 
INSERT OVERWRITE TABLE partition_table PARTITION (sex) 
SELECT sid, sname, age, sex 
FROM student1; 
+0

加入分区是不必要的。查询自动执行。 – syadav

+0

你可以看到他的错误说没有找到分区'M'。在我的第二个解决方案中,您可以看到我推荐的动态分区。你在第四行停止阅读了吗? – invoketheshell

+0

你的答案是非常有用的,但是当我尝试'ALTER TABLE partition_table ADD PARTITION(sex ='xxx'); ' - 它导致了一个新的错误'FAILED:执行错误,从org.apache.hadoop.hive.ql.exec.DDLTask返回代码1。 MetaException(消息:对于直接MetaStore数据库连接,我们不支持在客户端级别重试。) '但是我已经设置了'蜂房的site.xml'< property> \t < name> javax.jdo.option.ConnectionURL < /name> \t < value> JDBC:MySQL的:// djt01:3306 /蜂房的characterEncoding = UTF-8 < /value> \t <描述> JDBC连接串为JDBC metastore < /property> –

0

查询是正确的。但是一旦检查了表中的性别='M'值。这可能是不同的性价值。