Dean
Dean

Reputation: 9128

Can I recreate an Athena table without exposing an empty table?

I'd like to make changes to an Athena table which aren't possible with ALTER TABLE statements. This means dropping the current table and replacing it with a new one.

Between dropping the current table and creating the new one, anyone querying that table will get an error. This is fine.

The issue is that after creating the table, anyone querying it will see no rows until MSCK REPAIR or ADD PARTITION is run. This is not fine, because it has the potential of going unnoticed and causing downstream issues.

I'd like to avoid having to make these changes during a "maintenance window". Is it possible to somehow add the partitions atomically along with the create statement?

I've looked into using views on top of these tables and exposing those, but would prefer to avoid the extra layer if at all possible.

Upvotes: 1

Views: 934

Answers (1)

Theo
Theo

Reputation: 132972

To the best of my knowledge you cannot create a table and add partitions at the same time, and you cannot rename tables (which would have been another option, double buffering style). What you can do is use the Glue APIs directly to create the table and partitions, that will minimise the amount of time the table exists without partitions. With CreateTable followed by BatchCreatePartition the window where there are no partitions in the table will be as short as it can be.

Upvotes: 1

Related Questions