HIVE 如何迁移已有表的hdfs路径
背景:因为系统是个大数据平台,会有很多不同的生产厂家在HIVE中建表,因此需要有个规范来约束厂家存放数据,
因有些厂家把数据存放到了公共目录,现在需要迁移出指定的目录,不知道有没有啥方法;
以下为具体问题描述
1、厂家Y建了个表A
create table a(f1 int,f2 int,……) partition(xx,yy) location '/usr/hive/warehouse/a';
需要迁移A表的数据至 '/usr/hive/warehouse/厂家Y‘ ;
2、在直接更改location (alter table a set location '/usr/hive/warehouse/厂家Y/a‘ ) 发现hdfs的路径并没有变化;
在外网上查到一些方法:
1、新建一个表B,指定location到目标路径 create table b like a location '/usr/hive/warehouse/厂家Y/B';
2、迁移A的数据至B,
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
因为表A或者其他表有大量的分区,这样设置,可以自动在表B上维护分区
insert overwrite table B partition(xx,yy) select * from A;
3、drop 原来的表A drop table a;
4、更名表B为A, alter table b rename to a;
在步骤4之前,B的数据存放目录还是在 '/usr/hive/warehouse/厂家Y/B' 下,但是执行4后,表A(原表B)数据存放目录又变回了
'/usr/hive/warehouse/a' 下,结果失败了;
请问大家有没有啥好方法,谢谢了!