當我們創建好一個分區表的時候:
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)