hive为什么insert into后数据被覆盖了

在Hive中遇到INSERT INTO语句导致数据被覆盖的问题,博主进行了测试以理解其行为。通过创建测试表并使用INSERT OVERWRITE及INSERT INTO,发现数据并未被覆盖而是增加。最终,数据插入操作按预期进行,没有数据丢失。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

想在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,数据依旧只是增加,而不是覆盖。额,搞不懂了???

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值