[英]HIVE “show partitions” command do not show correct partitions
i have a partition table with dynamic partitions, partition fields are nationality and birthdate, 我有一个带有动态分区的分区表,分区字段是国籍和生日,
when i use select * from emp_new where nationality='China'
, i get the following three records, 当我使用
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 |
but when i run show partitions emp_new partition(nationality='China')
, i get the following results: 但是当我运行
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 |
+-------------------------------------+--+
Actually, I loaded the data into this table with static and dynamic partitions (nationality='China', birthdate)
earlier, then truncated the table and reload with dynamic partitions (nationality, birthdate)
later. 实际上,我早些时候将数据带有静态和动态分区
(nationality='China', birthdate)
加载到该表中,然后将其截断并稍后再加载了动态分区(nationality, birthdate)
。
I don't understand why the old partitions are still there. 我不明白为什么旧的分区仍然存在。
Truncate
deletes the table's data files. Truncate
删除表的数据文件。
It does not delete the partitions definitions from the metastore. 它不会从元存储中删除分区定义。
It does not delete the file system directories. 它不会删除文件系统目录。
Demo 演示
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
我知道原因,我需要在截断表后删除分区,谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.