Dropping multiple partitions in Impala/Hive

前端 未结 1 354
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 16:29

1- I\'m trying to delete multiple partitions at once, but struggling to do it with either Impala or Hive. I tried the following query, with and without \':

相关标签:
1条回答
  • 2020-12-29 16:47

    1.

    Your syntax is wrong.
    In the DROP command the partitions should be separated by commas.

    Demo

    hive> create table t (i int) partitioned by (p int);
    OK
    
    hive> alter table t add partition (p=1) partition(p=2) partition(p=3) partition(p=4) partition(p=5);
    OK
    
    hive> show partitions t;
    OK
    partition
    p=1
    p=2
    p=3
    p=4
    p=5
    
    hive> alter table t drop if exists partition (p=1),partition (p=2),partition(p=3);
    Dropped the partition p=1
    Dropped the partition p=2
    Dropped the partition p=3
    OK
    
    hive> show partitions t;
    OK
    partition
    p=4
    p=5
    

    2.

    You can drop a range.

    Demo

    hive> create table t (i int) partitioned by (p int);
    OK
    
    hive> alter table t add partition (p=1) partition(p=2) partition(p=3) partition(p=4) partition(p=5);
    OK
    
    hive> show partitions t;
    OK
    partition
    p=1
    p=2
    p=3
    p=4
    p=5
    
    hive> alter table t drop if exists partition (p<=3);
    Dropped the partition p=1
    Dropped the partition p=2
    Dropped the partition p=3
    OK
    
    hive> show partitions t;
    OK
    partition
    p=4
    p=5
    
    0 讨论(0)
提交回复
热议问题