col_1 | col_2 | col_3 | col_4 | ds |
ds类型为string,已有数据20191201 到20191231
TRUNCATE TABLE a;
清空全部数据,保留表结构
INSERT OVERWRITE TABLE a SELECT FROM a WHERE 1=2;
INSERT OVERWRITE TABLE a SELECT FROM a WHERE Col <> 1;
insert overwrite table a
select *
from a
where ds<20191220;
insert into table a
select *
from a
where ds>=20191211;
insert overwrite table a
select *
from a
where ds<20191210
union all
select *
from a
and ds>20191220;
ALTER TABLE table_name DROP [IF EXISTS] PARTITION (partition_spec);
partition_spec:(partition_col1 = partition_col_value1, partition_col2 = partiton_col_value2, ...)
INSERT OVERWRITE TABLE a PARTITION(ds= '20191231')
SELECT col_1
,col_2
,col_3
,col_4
,col_5
FROM a
WHERE 1 = 2
AND ds = '20191231'
;
insert overwrite table a partition (ds=20191231')
select col_1
,col_2
,col_3
,col_4
,col_5
from a
where col_1<>123
and ds='20191231';
一般用来更新表,比如某段时间的数据有错误,就要这种方法进行更新
insert overwrite table a PARTITION(ds)
select *
from b
where ds>0
insert overwrite table a PARTITION(ds)
select *
from b
where ds>=20191220;
insert overwrite table a PARTITION(ds)
select *
from b
where ds<=20191210;
insert overwrite table a PARTITION(ds)
select *
from b
where ds between 20191210 and 20191220;
将b表12月10号到20号的数据插入到a 表中
insert overwrite table a
select *
from b
where ds between 20191210
and 20191220;
insert overwrite table a partition (ds)
select *
from b
where ds between 20191210
and 20191220;
注意:
INSERT OVERWRITE TABLE a PARTITION(ds)
SELECT col_1
,col_2
,col_3
,col_4
,col_5
,ds
FROM temp_test_b
WHERE ds = '20191231'
;
INSERT OVERWRITE TABLE a PARTITION(ds='20191231')
SELECT col_1
,col_2
,col_3
,col_4
,col_5
FROM temp_test_b
WHERE ds = '20191231'
;
参考资料:
https://help.aliyun.com/knowledge_detail/150534.html?spm=5176.13910061.0.0.6e709179ssnlIl&aly_as=CvQU-xjIb#title-l37-w96-zdf