我正在寻找一种方法来删除与当天相关的分区。
alter table table_name drop partition(rep_date < from_unixtime(unix_timestamp(),'yyyy-MM-dd'));
这会返回错误:
无法识别附近的输入(unix ...
我可以做到这一点,而不是直接输入'2017-06-14'。我可以把它变成一个字面型吗?我什么时候试着把'cast'放在里面呢?不喜欢它?
答案 0 :(得分:2)
<强>蜂房强>
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 |
+---------------+