插入配置单元分区表SemanticException

Hbn*_*ing 1 hadoop hive

首先,我创建一个配置单元分区表:

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
Run Code Online (Sandbox Code Playgroud)

表desc如下所示:

 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)
Run Code Online (Sandbox Code Playgroud)

然后将一些数据插入此表中,但是它不起作用。

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''
Run Code Online (Sandbox Code Playgroud)

为了避免这种情况,我编写了以下命令,然后执行了我的插入命令,即使我反复遇到相同的错误。

set exec.dynamic.partition=true;                                                                           
set exec.dynamic.partition.mode=nonstrict;
Run Code Online (Sandbox Code Playgroud)

inv*_*ell 6

加载前添加分区:

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';
Run Code Online (Sandbox Code Playgroud)

或尝试动态分区:

set hive.exec.dynamic.partition=true;
INSERT OVERWRITE TABLE partition_table PARTITION (sex)
SELECT sid, sname, age, sex
FROM student1;
Run Code Online (Sandbox Code Playgroud)