HIVE"显示分区"命令不显示正确的分区

时间:2017-09-01 00:43:13

标签: hive partition

我有一个带动态分区的分区表, 分区是国籍和生日,

当我使用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)重新加载。

我不明白为什么旧分区仍在那里。

2 个答案:

答案 0 :(得分:1)

Truncate删除表格的数据文件 它从Metastore中删除分区定义 删除文件系统目录。

<强>演示

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

答案 1 :(得分:0)

我知道原因, 我需要在截断表后删除分区, 感谢