Lesson 4 of 6 AWS Glue

Checking Data Quality with AWS Glue Data Quality

This lesson explains how AWS Glue Data Quality evaluates declarative rules, inside ETL jobs or against Data Catalog tables, to check that data meets expectations before it is published, and reports the results for alerting and gating.

Learning outcomes

After completing this lesson, you will be able to:

  • Write rules in DQDL.
  • Choose where rules run: on catalogue tables or inside jobs.
  • Use rule recommendations and dynamic rules.
  • Act on results by quarantining rows or stopping a job.

Writing rules in DQDL

Glue Data Quality rules are written in the Data Quality Definition Language (DQDL), in short readable statements. IsComplete checks that a column has no missing values, and IsUnique checks that it has no duplicates, as an order ID should not. ColumnValues checks that values fall within a range, such as amounts above zero. RowCount checks the expected volume, which catches a load that silently produced too few rows. ReferentialIntegrity and DatasetMatch check consistency with another dataset, and DataFreshness checks that the newest records are recent enough. The following table summarises these rule types.

RuleChecks
IsComplete "order_id"No missing values
IsUnique "order_id"No duplicate values
ColumnValues "amount" > 0Values within a range
RowCount > 1000Expected volume
ReferentialIntegrity, DatasetMatchConsistency with another dataset
DataFreshnessTimeliness of the latest records
Match the pairs

DQDL rules

Exam skills 3.4.2

Match each requirement with the DQDL rule that checks it.

Log in to try this activity Interactive activities are free with an account.

Where rules run

Glue Data Quality can check data at two points. Rulesets attached to Data Catalog tables run on demand or on a schedule and check data already stored, which suits monitoring the quality of data at rest. Inside ETL jobs, the Evaluate Data Quality transform checks data as it flows through the pipeline and reports results for each row, so the job can stop, or send failing rows to a quarantine location, before bad data reaches consumers. The following table summarises the two options.

LocationHowUse for
Data Catalog tablesRulesets attached to a table, run on demand or on a scheduleMonitoring data at rest
Inside ETL jobsThe Evaluate Data Quality transform in Glue Studio or codeGating data as it flows, with row-level results

The following diagram shows the two points at which rules check data.

The two places Glue Data Quality checks data. Inside an ETL job, the Evaluate Data Quality transform gates data in flight with row-level results, before it reaches consumers. On a Data Catalog table, a ruleset run on demand or on a schedule monitors data already stored.
A pipeline can use both: a gate in the job and monitoring at rest.
Scenario questions

Where to run rules

Exam skills 3.4.1 · 3.4.2

Choose where Glue Data Quality rules should run.

Log in to try this activity Interactive activities are free with an account.

Creating and adapting rules

Writing data quality rules from scratch is slow, and fixed thresholds go out of date as data grows. AWS Glue Data Quality helps with both problems. Rule recommendations analyse a dataset and suggest a starting ruleset, such as completeness and uniqueness checks for each column, which engineers then review and adjust.

Dynamic rules compare each run with recent history instead of a fixed number, for example RowCount > avg(last(10)) * 0.8, which fails if today's row count is more than 20% below the average of the last ten runs. Anomaly detection goes further: it learns the normal statistics of the data over time and flags unusual values without any threshold being set, which catches problems that nobody thought to write a rule for.

The following diagram shows a dynamic row count rule evaluating today's load.

A dynamic rule in action. The rule RowCount > avg(last(10)) * 0.8 compares today's row count with the average of the last ten runs, about 100,000 rows, so the threshold is about 80,000. Today's load of 70,000 rows fails the rule, although no fixed number was set.
The row counts are illustrative.
Match the pairs

Adapting rules

Exam skills 3.4.2 · 3.4.3

Match each need with the Glue Data Quality capability.

Log in to try this activity Interactive activities are free with an account.

Acting on results

Each evaluation produces a score and per-rule results, published to CloudWatch and EventBridge. Jobs can route failing rows to a quarantine prefix, stop when the score falls below a threshold, and notify data owners through EventBridge and SNS.

The following diagram shows the ruleset in the job and where the data goes after evaluation.

The customer feed gated by Glue Data Quality. The ETL job evaluates five rules; data that passes goes to the curated zone. If the ruleset fails, the job writes the data to a quarantine prefix, publishes the result to EventBridge and alerts the data owners through SNS.
The prefix names are illustrative.
Select all that apply

Acting on quality results

Exam skills 3.4.1 · 3.3.3

Identify what a pipeline can do with Glue Data Quality results.

Log in to try this activity Interactive activities are free with an account.
Worked example

Stopping bad data before it reaches reports

A daily customer feed sometimes arrives with missing emails and negative ages, which break the dashboards. The team adds the following Glue Data Quality rules in the ETL job.

Rules = [
    IsComplete "customer_id",
    IsUnique "customer_id",
    Completeness "email" > 0.95,
    ColumnValues "age" between 0 and 120,
    RowCount between 50000 and 200000
]

Rows that pass go to the curated zone; if the ruleset fails, the job writes the data to a quarantine prefix, publishes the result to EventBridge and alerts the data owners. Over time, rule recommendations and anomaly detection suggest further checks, such as a dynamic row count rule.

Check yourself

In which language are Glue Data Quality rules written?

Show answer

Data Quality Definition Language (DQDL).

Exam Tips

Remember for the exam

  • Data quality rules in pipelines are written in DQDL for Glue Data Quality.
  • To suggest rules from the data, use Glue Data Quality rule recommendations.
  • To gate data inside a job, use the Evaluate Data Quality transform.
  • Dynamic rules and anomaly detection catch unexpected changes without fixed thresholds.
  • Quarantine bad rows and alert their owners through EventBridge.