简体   繁体   English

按日期范围删除配置单元分区

[英]Drop hive partition by date range

I use hive-0.10.0-cdh-4.7.0 in my environment. 我在我的环境中使用hive-0.10.0-cdh-4.7.0。

I have a table named test store as sequence file and some partitions by date_dim like below: 我有一个名为test store的表作为序列文件,有一些分区由date_dim如下所示:

game=Test/date_dim=2014-07-01    
game=Test/date_dim=2014-07-11    
game=Test/date_dim=2014-07-21    
game=Test/date_dim=2014-07-31

I want to drop partitions between 2014-07-21 and 2014-07-30 in SQL command: 我想在SQL命令中删除2014-07-21和2014-07-30之间的分区:

alter table test drop partition (date_dim>='2014-07-11',date_dim<='2014-07-30')

I hope these 2 partitions be deleted: 我希望删除这两个分区:

game=Test/date_dim=2014-07-11    
game=Test/date_dim=2014-07-21

But actually, these 3 partitions be deleted: 但实际上,这三个分区将被删除:

game=Test/date_dim=2014-07-01
game=Test/date_dim=2014-07-11
game=Test/date_dim=2014-07-21

It seems hive drop partition only use the date_dim<='2014-07-30' condition. 看来hive drop partition只使用date_dim<='2014-07-30'条件。

Is there anyway to make hive drop partition as I wish? 反正有没有按照我的意愿制作蜂巢掉落分区?

您应该将字符串转换为日期类型,为此您可以使用unix_timestamp函数:

alter table test drop partition (unix_timestamp(date_dim,'yyyy-MM-dd')>=unix_timestamp('2014-07-11','yyyy-MM-dd'),unix_timestamp(date_dim,'yyyy-MM-dd')<=unix_timestamp('2014-07-30','yyyy-MM-dd'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM