1)先把原来的表结构给查询出来
show create table `stg.stg_cccc_pm_pj_position_i_d`;
create table `stg.stg_cccc_pm_pj_position_i_d`(
`id` string DEFAULT NULL COMMENT '主键',
`flag` string DEFAULT NULL COMMENT '数据状态标识'
)
comment '项目管理_工程部位'
partitioned by (etl_date string comment '分区字段')
clustered by (id) into 3 buckets
stored as orc;
2)在原来的表名上添加_tmp后缀
create table `stg.stg_cccc_pm_pj_position_i_d_tmp`(
`id` string DEFAULT NULL COMMENT '主键',
`flag` string DEFAULT NULL COMMENT '数据状态标识'
)
comment '项目管理_工程部位'
partitioned by (etl_date string comment '分区字段')
clustered by (id) into 3 buckets
stored as orc;
3)从旧表中查询数据,装载到新表
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
insert into stg.stg_cccc_pm_pj_position_i_d_tmp partition(etl_date)
select * from stg.stg_cccc_pm_pj_position_i_d;
4)删除旧表
drop table stg.stg_cccc_pm_pj_position_i_d;
5)把_tmp后缀名给去掉
alter table stg.stg_cccc_pm_pj_position_i_d_tmp rename to stg.stg_cccc_pm_pj_position_i_d ;
6)瞧一眼数据
select * from stg.stg_cccc_pm_pj_position_i_d