hive 分区表msck命令

当我们创建好一个分区表的时候:

CREATE external TABLE IF NOT EXISTS db01.employees( name STRING COMMENT 'Employee name', salary FLOAT COMMENT 'Employee salary') partitioned by (country string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
location '/db/01/employees'

此时假如我们在/db/01/employees路径下新增加一个文件夹名为country=china,即现在有文件夹为
/db/01/employees/country=china,然后我们直接上传文件到这个文件夹下,hive是不会识别出来的,此时如果查询partitions得到的结果如下

hive> show partitions employees;
OK
partition
Time taken: 0.172 seconds

从结果看出此时该表没有分区,也就意味者/db/01/employees/country=china文件夹下的数据没有被识别出来,此时我们需要使用下面的命令让hive增加这个分区

hive> msck repair table employees;
OK
Partitions not in metastore:    employees:country=china
Repair: Added partition to metastore employees:country=china
Time taken: 0.303 seconds, Fetched: 2 row(s)

接着我们查看partitions得到信息如下:

hive> show partitions employees; OK partition country=china Time taken: 0.134 seconds, Fetched: 1 row(s)

你可能感兴趣的:(hive,repair,msck)