【问题标题】:Dropping a range of partitions in HIVE在 HIVE 中删除一系列分区
【发布时间】:2015-10-16 13:26:39
【问题描述】:

我有一个按日期列分区的 Hive(版本 0.11.0)表,类型为字符串。我想知道 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');

【问题讨论】:

    标签: hive hql


    【解决方案1】:

    我试过这个语法,它奏效了。

    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

    【讨论】:

    • 认为这会把所有东西都丢在桌子上?大于 201-04-14 或小于 2018-04-16...
    • @HeinduPlessis 这是 AND 不是 OR。示例:日期>'2018-04-14' 和日期
    • @HeinduPlessis,不,它不会删除其他分区,它只会删除介于两者之间的分区
    • @vreyespue 我认为两者都有用 - 你的脚本更加动态,但对于 OP(和我)的要求,这个答案更容易应用。
    • @Kharthigeyan 确实我从来没有意识到这是一个 AND 逻辑。
    【解决方案2】:

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

    【讨论】:

    • 这里有什么 date1、date2 和 myDate。假设您要在 2018-11-01 和 2019-02-12 之间删除?
    • Alter table mytable drop partition (myDate > '2018-11-01' , myDate
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多