AWS Certified Data Engineer – AssociateData Storage and ManagementMedium

A data engineering team manages a large data lake on Amazon S3. They use AWS Glue Data Catalog to store metadata for tables, which are partitioned by `year/month/day`. They observe that their Athena queries against these tables are performing poorly and scanning much more data than expected, even when filtering on specific dates. Upon investigation, they find that the Glue Data Catalog is not accurately reflecting the actual partitions on S3. What is the most efficient way to refresh the Glue Data Catalog to ensure partitions are correctly recognized for improved query performance?

  1. AUse `MSCK REPAIR TABLE` in Athena or Presto to update the Glue Data Catalog for the table.
  2. BImplement a Lambda function triggered by S3 events to call `aws glue batch-create-partition` for new folders.
  3. CManually add each new partition using the Glue console or AWS CLI `aws glue create-partition` command.
  4. DRun an AWS Glue Crawler on the S3 path of the table to discover new partitions.
Show answer & explanation

Correct answer: A. Use `MSCK REPAIR TABLE` in Athena or Presto to update the Glue Data Catalog for the table.

`MSCK REPAIR TABLE` is a command available in Athena and Presto that scans the S3 location of a table and adds any newly discovered partitions to the AWS Glue Data Catalog. This is often the most efficient way to refresh partitions for existing tables, especially when dealing with many new partitions, without needing to run a full Glue Crawler or develop custom Lambda functions.

Why the other options are wrong

  • B. Implementing a Lambda function is a valid approach for automated, real-time partition updates, but for a general 'refresh' scenario, `MSCK REPAIR TABLE` is a simpler, built-in, and often more efficient solution.
  • C. Manually adding partitions is feasible for a few new partitions but becomes unmanageable and error-prone for frequent or large numbers of new partitions.
  • D. Running a Glue Crawler can discover new partitions, but it is often overkill and slower than `MSCK REPAIR TABLE` if only partitions need to be updated for an existing table.

MSCK REPAIR TABLE

The `MSCK REPAIR TABLE` command (available in Athena/Presto/Hive) scans the underlying data location (e.g., S3) for a partitioned table and updates the AWS Glue Data Catalog with any new partitions it discovers.

  • Used to add new partitions to the Glue Data Catalog.
  • Scans the S3 path of a table based on its partition scheme.
  • Essential for improving query performance by making all data discoverable.
  • More efficient for partition updates than running a full Glue Crawler.
  • Does not remove stale partitions; for that, you might need `ALTER TABLE ... DROP PARTITION`.

Memory trick: MSCK repair, makes partitions fair, for queries to declare.

More Data Storage and Management questions