tbls --元数据的表信息
partitions --元数据的表分区信息
第一步【使用时忽略第一步,从第二步开始】
通过关联tbls表和partitions表,我们可以得到这张表所有分区对应的存储信息sd_id。
得到表的存储信息sd_id
select
t1.sd_id
from
tbls t1
where
tbl_name = 'dwd_beforeloan_third_combine_id'得到表分区的存储信息sd_id
select
distinct t2.sd_id
from
tbls t1
join
partitions t2
on t1.tbl_id = t2.tbl_id
where
t1.tbl_name = 'dwd_beforeloan_third_combine_id'
sds --存储信息表
第二步:观察存储信息表的数据可以发现,存储信息表由sd_id作为主键,但对于同一表字段结构的分区来说,cd_id也是这张表这些分区在存储信息表中的共同主键。【注意,有些表,不同分区表字段的结构不一样,所以对应的cd_id也是不一样的】
我们找出这张表目前有几套表字段结构
先看看表本身
select
distinct cd_id
from
sds t110
join
(
select
t1.sd_id
from
tbls t1
where
tbl_name = 'dwd_beforeloan_third_combine_id'
) t120
on t110.sd_id = t120.sd_id--结果cd_id = 361578
再结合表分区看看
select
distinct cd_id
from
sds t110
join
(
select
distinct t2.sd_id
from
tbls t1
join
partitions t2
on t1.tbl_id = t2.tbl_id
where
t1.tbl_name = 'dwd_beforeloan_third_combine_id'
) t120
on t110.sd_id = t120.sd_id--结果cd_id = 361578
第三步:正常情况下,一张分区表所有分区的字段结构都相同的,cd_id是同一个
我们找出这个表字段结果,对应的所有存储信息,并修改这些存储信息中,对应的hdfs存储路径
update SDS set LOCATION = REPLACE(LOCATION, 'xxx', 'new_xxx') where cd_id = '361578'
第四步:重命名hdfs表路径
hadoop fs -mv /user/hive/warehouse/xx.db/xxx /user/hive/warehouse/xx.db/new_xxx
第五步:修改元数据表名称
update TBLS set TBL_NAME = 'new_xxx' where TBL_NAME = 'xxx';
561

被折叠的 条评论
为什么被折叠?



