使用MSCK命令修复Hive表分区

来源:互联网 发布:unity3d apk 资源提取 编辑:程序博客网 时间:2024/04/28 04:37

一、介绍

我们平时通常是通过alter table add partition方式增加Hive的分区的,但有时候会通过HDFS put/cp命令往表目录下拷贝分区目录,如果目录多,需要执行多条alter语句,非常麻烦。Hive提供了一个"Recover Partition"的功能。

具体语法如下:

MSCK REPAIR TABLE table_name;
原理相当简单,执行后,Hive会检测如果HDFS目录下存在但表的metastore中不存在的partition元信息,更新到metastore中。


二、测试

#当前没有partition元信息hive> show partitions cr_cdma_bsi_mscktest;OKTime 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;OKPartitions not in metastore:cr_cdma_bsi_mscktest:month=201603Partitions not in metastore:cr_cdma_bsi_mscktest:month=201604Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201603Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201604Time taken: 0.286 seconds, Fetched: 2 row(s)#再次查看,发现已经成功更新元信息hive> show partitions cr_cdma_bsi_mscktest;OKmonth=201603month=201604Time taken: 0.102 seconds, Fetched: 1 row(s)


相关JIRA:HIVE-874

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

0 0
原创粉丝点击