如何在hive中同时删除所有分区?

Sur*_*aja 11 hive hive-partitions

Hive 1.1版

我有一个蜂巢外部表如下

 CREATE EXTERNAL TABLE `schedule_events`(
  `schedule_id` string COMMENT 'from deserializer',
  `service_key` string COMMENT 'from deserializer',
  `event_start_date_time` string COMMENT 'from deserializer',
  `event_id` string COMMENT 'from deserializer',
  `event_type` string COMMENT 'from deserializer',
  `transitional_key` string COMMENT 'from deserializer',
  `created_date_time` string COMMENT 'from deserializer',
  `bus_date` string COMMENT 'from deserializer')
    PARTITIONED BY (
                    `year` string,
                    `month` string,
                    `day` string)
   ROW FORMAT SERDE
   'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
   STORED AS INPUTFORMAT
   'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
   OUTPUTFORMAT
   'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
   LOCATION
   'hdfs://nameservice1/hadoop/raw/omega/scheduled_events'
  TBLPROPERTIES (
    'avro.schema.url'='hdfs:////hadoop/raw/omega/schema/schedule_events.avsc',
   'transient_lastDdlTime'='1505742141')
Run Code Online (Sandbox Code Playgroud)

现在要删除一个特定的分区,我可以运行ALTER命令,如下所示

 ALTER TABLE schedule_events DROP IF EXISTS PARTITION  (year='2016',month='06',day='01')
 Dropped the partition year=2016/month=06/day=01

 hive> show partitions schedule_events;
 OK
 year=2017/month=09/day=01
 year=2017/month=09/day=02
 year=2017/month=09/day=03
 year=2017/month=09/day=04
 year=2017/month=09/day=05
Run Code Online (Sandbox Code Playgroud)

但是这个表有很多分区

如何一次删除所有现有分区?我想一次删除所有现有分区?那可能吗?

Dav*_*itz 21

有多种选择,这里有一个:

alter table schedule_events drop if exists partition (year<>'');
Run Code Online (Sandbox Code Playgroud)

Hive:扩展ALTER TABLE DROP PARTITION语法以使用所有比较器

"...要从Hive表中删除分区,这可以工作:
ALTER TABLE foo DROP PARTITION(ds ='date')
...但它也可以在日期之前删除所有分区
.ALTER TABLE foo DROP PARTITION( ds <'date')此任务是为所有比较器实现ALTER TABLE DROP PARTITION,<> <=> = <> =!=而不仅仅是for ="

https://issues.apache.org/jira/browse/HIVE-2908

  • 公平地说,尽管两者之间的差异在这里无关紧要。关键是错误是由于使用单引号而不是双引号造成的,并且从错误消息本身来看并不明显。否则,Hive 或 Presto(以及 Athena)的语法相同 (2认同)

Ani*_*non 8

您可以使用与此类似的东西:

ALTER TABLE schedule_events drop if exists partition (year>'0');
Run Code Online (Sandbox Code Playgroud)