Support Questions

Find answers, ask questions, and share your expertise

how can i delete older partitions data in hive

avatar
Expert Contributor

i want to delete the older partitons data more than 10 days. my script runs everyday. iam able to truncate the partitioned managed table with the current date but unable to truncate more than 10 days data from current date. Can anyone provide me the command to truncate the date with date a partitioned column for more than 10 days

3 REPLIES 3

avatar
Expert Contributor

You may use the linux script to loop over the date that more than 10 days, and use "truncate table [tablename] partition [date partition]". And if you can run everyday, you just need to run one truncate.

avatar
Expert Contributor

Hi Frank lu

Can you provide me the code with the example i didnt exactly what you are saying

avatar

Hi Dinesh,

You can use this set hive.variable.substitute=true; set hiveconf:my_date=date_sub(current_date, 10); truncate table table_name parition (date=${hiveconf:my_date});

Hope this will help.

Regards

Niranjan