4

My partitions look like these

event_year=2019/event_week=37/event_date=2019-09-10
event_year=2019/event_week=42/event_date=2019-10-13
event_year=2019/event_week=8/event_date=2019-02-20
event_year=2020/event_week=24/event_date=2020-06-15

There are 1500 partitions like this how do I drop all the partitions at once?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
abcsjdj26
  • 41
  • 1
  • 2

2 Answers2

5

The easiest and quickest way is to drop the table and recreate it. You can get the DDL with SHOW CREATE TABLE table_name if you don't have it.

If you really need to drop partitions and not the table the most efficient way is to use the Glue Data Catalog APIs to first list all partitions and then delete partitions in batches of 25.

Theo
  • 131,503
  • 21
  • 160
  • 205
1

It's not documented anywhere but sometimes in athena you can drop all partitions with

ALTER TABLE table_name DROP PARTITION (not_a_column=NULL)

This appears to be a side effect of being able to only specify one partition if you have a table partitioned on multiple dimensions.

If the above doesn't work then I fallback to using the awswrangler python library https://aws-sdk-pandas.readthedocs.io/en/stable/stubs/awswrangler.catalog.delete_partitions.html

Crazometer
  • 457
  • 7
  • 12