Great Expectations and Pipeline Validation

Validate data in Python and Spark pipelines with Great Expectations (or similar tools like Soda and pandera): expectations, suites, checkpoints and data docs.

Intermediate · about 5 hours · difficulty 3/5

Learn first: Data Quality Fundamentals, Orchestration Concepts

Not all data passes through dbt. Raw files, Spark jobs and Python ingestion also need validation, and Great Expectations (GX) is the most known open source tool for it.

Core concepts

  • Expectations: declarative assertions such as expect_column_values_to_not_be_null, expect_column_values_to_be_between, expect_table_row_count_to_be_between, expect_column_values_to_match_regex.
  • Expectation suites: a set of expectations for a dataset.
  • Data sources and batches: connect GX to pandas, Spark or SQL and select the data to validate.
  • Checkpoints or validation definitions: run a suite against a batch and trigger actions (alerts, stopping the pipeline).
  • Data Docs: generated HTML reports of results.

Where it fits

  • Validate raw files right after ingestion, before loading into silver.
  • Validate Spark DataFrames before writing.
  • Call validation as a task in your orchestrator and fail the DAG on errors.

Alternatives

  • Soda Core: checks written in a YAML-based language (SodaCL).
  • pandera: schema and value validation for pandas and Polars DataFrames in code.
  • dbt tests for warehouse models.

Pick based on where your data lives; concepts are the same.

Pitfalls

  • Auto-generating hundreds of expectations from a profile and never reviewing them.
  • Running validation but not acting on failures.
  • API changes between major GX versions; check the docs for your version.

You are ready to move on when you can add a validation step to your Airflow or Prefect pipeline that checks a raw file with a suite of at least six expectations and stops the run when they fail.

Key concepts

  • Expectations
  • Expectation suites
  • Data sources and batches
  • Checkpoints and actions
  • Data Docs
  • Soda Core
  • pandera

Mini project

Add a Great Expectations (or pandera) validation task to your orchestrated pipeline that checks the raw extract for row count, null keys, value ranges and a regex on IDs. Make the DAG fail on errors and publish Data Docs.

Check yourself

Why would you validate raw files with a tool like Great Expectations even if you already have dbt tests on the warehouse models?

Free resources