添加分區 alter table user_bhv add if not exists partition (month="2020-03");
刪除分區 alter table user_bhv drop partition (month='2020-03');
修復分區 msck repair table user_bhv;
查看所有分區 show partitions user_bhv;
查看錶信息 desc formatted user_bhv;
查看分區實際保存位置 describe formatted user_bhv partition (month="2020-02");
備註:
- 使用
msck
命令修復分區時只會自動識別添加形如/tablename/{partition-name}=XXXXX
的數據目錄,其他格式是不會識別的 - 如果使用
alter table user_bhv add if not exists partition (month="2020-03");
命令創建新分區,hive會降分區目錄指向hdfs://mycluster/XXX/month=2020-03
這裏,如果這個目錄不存在(比如實際的目錄是mycluster/XXX/2020-03
),創建過程不會報錯但是會取不到數據 - 可使用
alter table user_bhv add if not exists partition (month="2020-03") location "hdfs://mycluster/XXX/2020-03";
命令指定數據location並創建分區