在 HIVE 中删除一系列分区

Dropping a range of partitions in HIVE

我有一个 Hive(版本 0.11.0)table 按列日期分区,类型为字符串。我想知道 Hive 中是否存在一种方法可以删除某个日期范围内的分区(比如从 'date1' 到 'date2')。我尝试了以下(SQL 类型)查询,但它们在语法上似乎不正确:

ALTER TABLE myTable DROP IF EXISTS PARTITION
(date>='date1' and date<='date2');

ALTER TABLE myTable DROP IF EXISTS PARTITION
(date>='date1' && date<='date2');

ALTER TABLE myTable DROP IF EXISTS PARTITION
(date between 'date1' and 'date2');

解决方案:alter table myTable drop partition (unix_timestamp('date1','yyyy-MM-dd')>unix_timestamp(myDate,‌​'yyyy-MM-dd'),unix_t‌​imestamp('date2','yy‌​yy-MM-dd')<unix_time‌​stamp(myDate,'yyyy-M‌​M-dd'));

我试过这个语法,它有效。

ALTER TABLE mytable DROP PARTITION (dates>'2018-04-14',dates<'2018-04-16');

命令输出:

    Dropped the partition dates=2018-04-15/country_id=107
    Dropped the partition dates=2018-04-15/country_id=110
    Dropped the partition dates=2018-04-15/country_id=112
    Dropped the partition dates=2018-04-15/country_id=14
    Dropped the partition dates=2018-04-15/country_id=157
    Dropped the partition dates=2018-04-15/country_id=159
    Dropped the partition dates=2018-04-15/country_id=177
    Dropped the partition dates=2018-04-15/country_id=208
    Dropped the partition dates=2018-04-15/country_id=22
    Dropped the partition dates=2018-04-15/country_id=233
    Dropped the partition dates=2018-04-15/country_id=234
    Dropped the partition dates=2018-04-15/country_id=76
    Dropped the partition dates=2018-04-15/country_id=83
    OK
    Time taken: 0.706 seconds

我正在使用 Hive 1.2.1000.2.5.5.0-157