如何删除具有动态值的配置单元分区

how to drop hive partitions with dynamic values

我正在寻找一种删除与当天相关的分区的方法。

alter table table_name drop partition(rep_date < from_unixtime(unix_timestamp(),'yyyy-MM-dd'));

这returns一个错误:

cannot recognise input near from(unix...

我可以在不按字面意思输入“2017-06-14”的情况下执行此操作。我可以将其转换为文字类型吗?当我尝试将 'cast' 放入其中时,它不喜欢它吗?

演示

蜂巢

create table mytable (i int) partitioned by (dt date)
;

alter table mytable add
    partition (dt=date '2017-06-11')
    partition (dt=date '2017-06-12')
    partition (dt=date '2017-06-13')
    partition (dt=date '2017-06-14')
    partition (dt=date '2017-06-15')
    partition (dt=date '2017-06-16')
    partition (dt=date '2017-06-17')
;

show partitions mytable
;

+---------------+
|   partition   |
+---------------+
| dt=2017-06-11 |
| dt=2017-06-12 |
| dt=2017-06-13 |
| dt=2017-06-14 |
| dt=2017-06-15 |
| dt=2017-06-16 |
| dt=2017-06-17 |
+---------------+

bash

hive --hivevar dt="$(date +'%Y-%m-%d')" -e 'alter table mytable drop partition (dt < date "${hivevar:dt}")'

...
Dropped the partition dt=2017-06-11
Dropped the partition dt=2017-06-12
Dropped the partition dt=2017-06-13
OK
Time taken: 1.621 seconds
...
bash-4.1$ 

蜂巢

show partitions mytable
;

+---------------+
|   partition   |
+---------------+
| dt=2017-06-14 |
| dt=2017-06-15 |
| dt=2017-06-16 |
| dt=2017-06-17 |
+---------------+