1. CREATE TABLE new_table LIKE old_table;
2. 使用Hadoop fs -cp 命令,把old_table对应的HDFS目录的文件夹全部拷贝到new_table对应的HDFS目录下;
3. 使用MSCK REPAIR TABLE new_table;修复新表的分区元数据;
- #当前没有partition元信息
- hive> show partitions cr_cdma_bsi_mscktest;
- OK
- Time taken: 0.104 seconds
- #创建两个分区目录
- hive> dfs -mkdir /user/hive/warehouse/cr_cdma_bsi_mscktest/month=201603;
- hive> dfs -mkdir /user/hive/warehouse/cr_cdma_bsi_mscktest/month=201604;
- #使用MSCK修复分区
- hive> msck repair table cr_cdma_bsi_mscktest;
- OK
- Partitions not in metastore: cr_cdma_bsi_mscktest:month=201603
- Partitions not in metastore: cr_cdma_bsi_mscktest:month=201604
- Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201603
- Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201604
- Time taken: 0.286 seconds, Fetched: 2 row(s)
- #再次查看,发现已经成功更新元信息
- hive> show partitions cr_cdma_bsi_mscktest;
- OK
- month=201603
- month=201604
- Time taken: 0.102 seconds, Fetched: 1 row(s)