使用MSCK命令修复Hive表分区

原文链接:http://blog.csdn.net/opensure/article/details/51323220

msck 命令也就是更新hive表的元数据。当表的分区命令存在,而在shell中看到不表的分区情况的时候,说明表的元数据没有更新,所以通msck表的操作可以更新表的元数据。

一、介绍

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

具体语法如下:

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


二、测试

[sql]  view plain  copy
  1. #当前没有partition元信息  
  2. hive> show partitions cr_cdma_bsi_mscktest;  
  3. OK  
  4. Time taken: 0.104 seconds  
  5. #创建两个分区目录  
  6. hive> dfs -mkdir /user/hive/warehouse/cr_cdma_bsi_mscktest/month=201603;  
  7. hive> dfs -mkdir /user/hive/warehouse/cr_cdma_bsi_mscktest/month=201604;  
  8. #使用MSCK修复分区  
  9. hive> msck repair table cr_cdma_bsi_mscktest;  
  10. OK  
  11. Partitions not in metastore:    cr_cdma_bsi_mscktest:month=201603  
  12. Partitions not in metastore:    cr_cdma_bsi_mscktest:month=201604  
  13. Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201603  
  14. Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201604  
  15. Time taken: 0.286 seconds, Fetched: 2 row(s)  
  16. #再次查看,发现已经成功更新元信息  
  17. hive> show partitions cr_cdma_bsi_mscktest;  
  18. OK  
  19. month=201603  
  20. month=201604  
  21. Time taken: 0.102 seconds, Fetched: 1 row(s)  


相关JIRA:HIVE-874

https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值