简体   繁体   English

从HIVE表动态删除分区

[英]drop partition dynamically from HIVE table

I have a hive table where partition exists on one of the date column, but date column is stored as INT in the format YYYYMMDD. 我有一个hive表,其中一个日期列存在分区,但日期列以YYYYMMDD格式存储为INT。 The table can also contain data for future date's partitions. 该表还可以包含未来日期分区的数据。

Now as part of the process I want to drop partitions which are fuing to usture days (sitting on the processing day). 现在作为整个过程的一部分,我想删除那些令人兴奋的分区(坐在处理日)。

So I am trying to use below 所以我想在下面使用

ALTER TABLE TABLE1 DROP IF EXISTS PARTITION (TBL_DATE >= CAST(REGEXP_REPLACE(CAST(DATE_SUB(TO_DATE('${load_date}'),1) AS STRING),'-','') AS INT));

means with date value 表示日期值

ALTER TABLE TABLE1 DROP IF EXISTS PARTITION (TBL_DATE >= CAST(REGEXP_REPLACE(CAST(DATE_SUB(TO_DATE('2016-09-11'),1) AS STRING),'-','') AS INT));

But it is failing. 但它失败了。

The output of the query is CAST(REGEXP_REPLACE(CAST(DATE_SUB(TO_DATE('2016-09-11'),1) AS STRING),'-','') AS INT) => 20160910 查询的输出是CAST(REGEXP_REPLACE(CAST(DATE_SUB(TO_DATE('2016-09-11'),1) AS STRING),'-','') AS INT) => 20160910

When I am writing my drop partitions like ALTER TABLE TABLE1 DROP IF EXISTS PARTITION (TBL_DATE >= 20160910) , then it is working fine. 当我编写我的drop分区时,如ALTER TABLE TABLE1 DROP IF EXISTS PARTITION (TBL_DATE >= 20160910) ,那么它工作正常。

Considering my input will be only date format YYYY-MM-DD and I have drop all partitions having given input date -1; 考虑到我的输入将只是日期格式YYYY-MM-DD并且我已经删除所有给定输入日期为-1的分区; how to make the above statement work. 如何使上述声明有效。

请先将其设置为非严格模式,然后动态执行,

SET hive.exec.dynamic.partition=nonstrict

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

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