2017-09-01 167 views
0

我有一個分區表,動態分區, 分區字段國籍,出生日期,HIVE「顯示分區」命令不顯示正確的分區

當我使用select * from emp_new where nationality='China',我得到以下三個記錄,

+---------------+--------------+--------------+------------------+----------------------+--------------------+--+ 
| emp_new.name | emp_new.sex | emp_new.age | emp_new.job | emp_new.nationality | emp_new.birthdate | 
+---------------+--------------+--------------+------------------+----------------------+--------------------+--+ 
| Tony   | M   | 34   | IT specialist | China    | 198202    | 
| Katrina  | F   | 33   | IT specialist | China    | 198408    | 
| Cathy   | F   | 30   | IT specialist | China    | 198704    | 

但是當我運行show partitions emp_new partition(nationality='China'),我得到如下結果:

+-------------------------------------+--+ 
|    partition    | 
+-------------------------------------+--+ 
| nationality=China/birthdate=198408 | 
| nationality=China/birthdate=198202 | 
| nationality=China/birthdate=198704 | 
| nationality=China/birthdate=197509 | 
| nationality=China/birthdate=196704 | 
| nationality=China/birthdate=197805 | 
| nationality=China/birthdate=198201 | 
| nationality=China/birthdate=197701 | 
| nationality=China/birthdate=196708 | 
+-------------------------------------+--+ 

其實,我加載將數據編輯到此表中,並在之前使用靜態和動態分區(nationality='China', birthdate),然後截斷表並在稍後使用動態分區(nationality, birthdate)重新加載。

我不明白爲什麼舊分區仍然存在。

+0

文本替換照片(格式它使用CTRL + K),並添加表DDL –

回答

1

Truncate刪除表格的數據文件。
不會刪除存儲區中的分區定義。
不會刪除文件系統目錄。

演示

hive> create table mytable (i int) partitioned by (p int); 
OK 

hive> insert into mytable partition (p) values (1,10),(2,10),(3,20),(4,30),(5,30),(6,30); 
OK 

hive> select * from mytable; 
OK 
mytable.i mytable.p 
1 10 
2 10 
3 20 
4 30 
5 30 
6 30 


hive> show partitions mytable; 
OK 
partition 
p=10 
p=20 
p=30 

hive> !tree ../local_db/mytable; 
../local_db/mytable 
├── p=10 
│   └── 000000_0 
├── p=20 
│   └── 000000_0 
└── p=30 
    └── 000000_0 

3 directories, 3 files 

hive> truncate table mytable; 
OK 

hive> select * from mytable; 
OK 
mytable.i mytable.p 

hive> show partitions mytable; 
OK 
partition 
p=10 
p=20 
p=30 

hive> !tree ../local_db/mytable; 
../local_db/mytable 
├── p=10 
├── p=20 
└── p=30 

3 directories, 0 files 
+0

謝謝,那麼如何截斷表,並在同一時間 刪除Metastore中的分區定義並刪除文件系統目錄? – tonyibm

+0

第一件事第一件事。你有沒有看到我對你的文章的評論? –

+0

剛更新了圖片 – tonyibm

0

我知道原因, 我需要刪除該分區截斷表後, 感謝