awswrangler.athena.repair_table(table: str, database: str | None = None, data_source: str | None = None, s3_output: str | None = None, workgroup: str = 'primary', encryption: str | None = None, kms_key: str | None = None, athena_query_wait_polling_delay: float = 1.0, boto3_session: Session | None = None) str

Run the Hive’s metastore consistency check: ‘MSCK REPAIR TABLE table;’.

Recovers partitions and data associated with partitions. Use this statement when you add partitions to the catalog. It is possible it will take some time to add all partitions. If this operation times out, it will be in an incomplete state where only a few partitions are added to the catalog.


Create the default Athena bucket if it doesn’t exist and s3_output is None. (E.g. s3://aws-athena-query-results-ACCOUNT-REGION/)


This function has arguments which can be configured globally through wr.config or environment variables:

  • database

  • athena_query_wait_polling_delay

  • workgroup

Check out the Global Configurations Tutorial for details.

  • table (str) – Table name.

  • database (str, optional) – AWS Glue/Athena database name.

  • data_source (str, optional) – Data Source / Catalog name. If None, ‘AwsDataCatalog’ is used.

  • s3_output (str, optional) – AWS S3 path.

  • workgroup (str) – Athena workgroup. Primary by default.

  • encryption (str, optional) – None, ‘SSE_S3’, ‘SSE_KMS’, ‘CSE_KMS’.

  • kms_key (str, optional) – For SSE-KMS and CSE-KMS , this is the KMS key ARN or ID.

  • athena_query_wait_polling_delay (float, default: 0.25 seconds) – Interval in seconds for how often the function will check if the Athena query has completed.

  • boto3_session (boto3.Session(), optional) – Boto3 Session. The default boto3 session will be used if boto3_session receive None.


Query final state (‘SUCCEEDED’, ‘FAILED’, ‘CANCELLED’).

Return type:



>>> import awswrangler as wr
>>> query_final_state = wr.athena.repair_table(table='...', database='...')