Hive刷分区MSCK 您所在的位置:网站首页 hive取最新分区 Hive刷分区MSCK

Hive刷分区MSCK

2024-07-17 06:06| 来源: 网络整理| 查看: 265

一、介绍

我们平时通常是通过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; 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 metas


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有