Lesson 03 Data Quality with Great Expectations
Theme:
Lesson 03 · Slide 1

Lesson 03 — Data Quality with Great Expectations

Catching the moment your data lies to you.

Data Engineering Module 1
Lesson 03 · Slide 2

The four kinds of broken data

Lesson 03 · Slide 3

Test in code vs test in data

Unit tests (code)

Check the code that processes data — gates the CI build.

Data-quality checks (data)

Check the data the code processed — gates the pipeline run.

Different lifecycles, different alerting. A unit test passing does not mean today's data is good.

Lesson 03 · Slide 4

The Great Expectations vocabulary

TermWhat it is
ExpectationA single assertion about data (e.g., "column X is never null").
SuiteA named bundle of expectations applied to one table.
CheckpointA scheduled run of a suite against fresh data.
Data docsGenerated HTML reports of run results.
Lesson 03 · Slide 5

A first expectation

import great_expectations as gx
context = gx.get_context()
dx = context.sources.add_pandas("gh").read_parquet("data/parquet/date=2024-01-01/")
result = dx.expect_column_values_to_not_be_null("type")
print(result.success)   # True

One call. One assertion. Returns a result object with success, observed value, and a sample of unexpected rows.

Lesson 03 · Slide 6

The Module 1 starter suite

Expectations to add to the gharchive events table:

Lesson 03 · Slide 7

Drift detection — expect_column_values_to_be_in_set

The set of GitHub event types changes slowly but does change (e.g., DiscussionEvent added in 2020). Pin the known set; let the expectation fail loudly when a new value appears; then decide whether to accept or reject the new type.

This is not a bug to fix in code — it is a data contract decision. Document it. Update the expectation. Tell downstream consumers.

Lesson 03 · Slide 8

What to do when validation fails

SeverityExampleAction
block-the-pipelinerequired column missingfail loudly; alert on-call; do not load downstream.
warn-but-loadnew event type appearedannotate the load; surface in dashboards; review in standup.
inforow count up 10% week-over-weekdashboard only; no alert.
Lesson 03 · Slide 9

Where it fits in the pipeline

extract -> transform -> [VALIDATE] -> load -> downstream

The validate step is between transform and load — sometimes also right after extract. On failure, the load step is skipped.

Lesson 03 · Slide 10

The L03 sample-pipeline shape

sample-pipeline/
  extract/
  transform/
  quality/
    expectations.py        # the suite
    checkpoints/           # GE-generated
    data_docs/             # GE-generated HTML
Lesson 03 · Slide 11

Common pitfalls

Lesson 03 · Slide 12

What this course is not doing today

Full schema contracts (Lesson 13), automated profiling (Lesson 12), CI integration of suites (Lesson 06). Today: a hand-written suite, running locally, against the L02 output.

One step at a time. The primitives you learn here are the building blocks for all of those advanced patterns.

Lesson 03 · Slide 13

Recap & what's next

Coming up: Module 2 — wrap all of this in Airflow.
1 / ?