【问题标题】:HIVE "show partitions" command do not show correct partitionsHIVE“显示分区”命令不显示正确的分区
【发布时间】:2017-09-01 19:21:44
【问题描述】:

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

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

我不明白为什么旧分区仍然存在。

【问题讨论】:

  • 将图片替换为文字(ctrl+k格式化)并添加表格DDL

标签: hive partition


【解决方案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

【讨论】:

  • 谢谢,那么如何截断表,同时从元存储中删除分区定义并删除文件系统目录?
  • 第一件事。你看到我对你帖子的评论了吗?
  • @tonyibm,表 DDL?
  • 创建表 emp_new(name string, sex string,age int, job string) 由 (nationality,birthdate) 分区的行格式分隔字段以 '|' 结尾以 ',' 终止的集合项
  • @tonyibm - 不,这不是工作代码。也将其添加到您的原始帖子中,而不是作为评论。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    相关资源
    最近更新 更多