想在jk_no_dubo_score表中插入部分数据,未插入数据前,数据数量为
插入数据后,数据数量为
我惊了???
我是这么写的
insert into table jk_no_dubo_score partition(stat_month='202108')
select serv_number,month,score
from hw_1_zyjk_qwsjxygj_101.jk_dubo_score
where stat_month='202108' and score=1 or score=4
;
明明是insert into,为什么被覆盖了,害的我还得重新跑!
网上查的
Hive insert into 竟然覆盖了原来的数据
但是我没有犯这个错误。
后面,我使用union all将两个表合并到一个新的表,但是我不明白insert into为什么覆盖数据了,于是写的一个测试表。
//创建一个空表
create table ld_mao_test_1009
(
serv_number string,
month string,
score string
)
partitioned by(stat_month string)
row format delimited fields terminated by '\t' ;
//对空表中插入数据
insert overwrite table ld_mao_test_1009 partition(stat_month='202108')
select serv_number,month,score
from jk_final_dubo_score
where stat_month='202108' and score=1
;
//使用insert into在表中添加数据,测试表中数量是否增加
insert into table ld_mao_test_1009 partition(stat_month='202108')
select serv_number,month,score
from jk_final_dubo_score
where stat_month='202108' and score=2
;
select count(1) from jk_final_dubo_score where stat_month='202108' and score=1;
// 2630
select count(1) from jk_final_dubo_score where stat_month='202108' and score=2;
//405654
select count(1) from ld_mao_test_1009 where stat_month='202108';
// 408284
但是,这次测试,数据并没有被覆盖。。。
我再次尝试inert into,数据依旧只是增加,而不是覆盖。额,搞不懂了???