2017-09-19 1 views
1

Hive-Version 1.1Wie kann ich alle Partitionen gleichzeitig in der Struktur löschen?

Ich habe einen Bienenstock externe Tabelle, wie unten

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') 

Jetzt eine bestimmte Partition löschen ich einen Befehl ALTEN wie unten

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 

kann laufen, aber diese Tabelle mit viele Partitionen

Wie lösche ich alle vorhandenen Partitionen auf einmal? Ich möchte alle vorhandenen Partitionen auf einmal löschen? Ist das möglich?

+0

Versuchen 'TABLE schedule_events DROP ALTER IF Partition (Jahr nicht null ist)' – Ambrish

+0

@Ambrish Ich glaube nicht, dass das funktionieren würde. Ihre Abfrage 'ALTER TABLE schedule_events DROP IF EXISTS PARTITION (Jahr ist nicht null)' würde prüfen, ob eine Partition 'year is not null' existiert, was falsch ist. –

Antwort

5

Es gibt mehrere Optionen, hier ist eine:

alter table schedule_events drop if exists partition (year<>''); 

Hive: ALTER TABLE DROP PARTITION Syntax Extend alle Komparatoren

“zu verwenden ... Um eine Partition aus einer Drop Hive-Tabelle, das funktioniert:
ALTER TABLE foo DROP PARTITION (ds = 'Datum')
... aber es sollte auch funktionieren, alle Partitionen vor dem Datum fallen zu lassen.
ALTER TABLE foo DROP PARTITION (ds < 'date') Diese Aufgabe ist ALTER TABLE DROP PARTITION für alle der Komparatoren, <> < => = <> =! = Statt nur für =“

zu implementieren

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

0

Sie können etwas ähnliches verwenden:

ALTER TABLE schedule_events drop if exists partition (year>'0'); 
Verwandte Themen