-1.创建分区转换临时表
CREATE TABLE my_schema.for_exchange
with (APPENDONLY=true, COMPRESSLEVEL=9)
as (select * from my_schema.current_partition)
DISTRIBUTED BY (day_id, fst_agc_offc_cd, carr_cd, flt_nbr);
--3.比较数据内容
select 'org',count(*) from my_schema.current_partition group by 1
union
select 'new',count(*) from my_schema.for_exchange group by 1
===============================================================
"new";35375423
"org";35375423
===========================================================
--4.交换分区
alter table my_schema.schl_pnrd_daily exchange partition month201303 with table my_schema.for_exchange
--5.检验交换无问题
select 'org',count(*) from my_schema.current_partition group by 1
union
select 'new',count(*) from my_schema.for_exchange group by 1
"new";35375423
"org";35375423
-- 6.删除交换出去的分区
drop table my_schema.for_exchange
CREATE TABLE dw1.t_m_user_ugc_playvideo_details
();
CREATE TABLE tempschema.t_m_user_ugc_playvideo_details
(
f_platform INTEGER,
f_uid CHARACTER VARYING,
f_day INTEGER,
f_hour INTEGER,
f_vid BIGINT,
f_catecode INTEGER,
f_userid CHARACTER VARYING,
f_videolength BIGINT,
f_site SMALLINT,
f_speed INTEGER,
f_suspend INTEGER,
f_backward INTEGER,
f_slide INTEGER,
f_playtime INTEGER
)
DISTRIBUTED BY (f_uid);
alter table dw1.t_m_user_ugc_playvideo_details
add partition p20141109 VALUES(20141109);
alter table dw1.t_m_user_ugc_playvideo_details drop partition if exists 20141109;
增量数据放到一个临时表里面:tempschema.t_m_user_ugc_playvideo_details,用该表的数据提供目的表:dw1.t_m_user_ugc_playvideo_detailsde 的分区如p20141109
alter table dw1.t_m_user_ugc_playvideo_details exchange partition p20141109
with table tempschema.t_m_user_ugc_playvideo_details ;