Skip to main content

Advanced Usage

This guide covers advanced patterns and configurations for Data Quality as Code, including loading tests from YAML files, customizing workflow configurations, and integrating with production systems.

Loading Tests from YAML

Load test definitions from YAML workflow files to enable version-controlled test configurations:

Basic YAML Loading

Use TestRunner.from_yaml() to load test definitions from a file or an inline YAML string.

Using Collate Connection from YAML

By default, from_yaml() uses the connection configured via configure(). To use the connection from the YAML file:

YAML File Structure

A complete YAML configuration includes:

Advanced TestRunner Configuration

Use these options to control runner behavior and inspect loaded test definitions.

Customizing Workflow Behavior

Use the setup() method to control logging, error handling, and success thresholds.

Accessing Test Definitions

Inspect configured tests before running:

Publishing Results to Collate

Results can be published back to Collate for tracking, alerting, and visualization:

DataFrame Validation Results

After validating a DataFrame, call publish() to send results to Collate.

Benefits of Publishing Results

Publishing results to Collate enables the following.
  • Historical tracking: View trends over time.
  • Alerting: Trigger notifications on failures.
  • Dashboards: Centralized data quality monitoring.
  • Collaboration: Share results across teams.
  • Compliance: Maintain audit trails.

Error Handling and Retries

Implement robust error handling:

Dynamic Test Generation

Generate tests programmatically based on metadata:

Multi-Table Validation

Validate multiple tables in a workflow:

Best Practices Summary

Follow these guidelines when building production data quality workflows.
  • Version-control test configurations: Store YAML test files in your git repository alongside your pipeline code. This keeps test definitions auditable, reviewable, and aligned with the code they validate.
  • Use environment variables for credentials: Never hardcode JWT tokens or connection strings in code. Read them from environment variables such as OPENMETADATA_JWT_TOKEN and OPENMETADATA_HOST so credentials stay out of source control.
  • Implement retries for transient failures: Network timeouts and temporary service unavailability are expected in production. Wrap TestRunner.run() calls in a retry loop with exponential backoff, and distinguish retryable errors (connection failures) from non-retryable ones (configuration errors).
  • Publish results after every run: Calling result.publish() sends test outcomes to Collate, where they appear in dashboards and trigger configured alerts. Without publishing, test runs are invisible to data stewards and stakeholders.
  • Monitor test execution time: Track how long test runs take over time. A sudden increase can indicate a growing dataset, a degraded connection, or a misconfigured test.
  • Handle errors explicitly: Catch and log specific exception types rather than letting all exceptions fail silently. Distinguish between configuration errors, which should stop the pipeline, and transient errors, which may be retried.
  • Use descriptive test names and descriptions: A test named customer_email_not_null with a description such as “Ensures all customer records have a valid email before loading to the warehouse” is far easier to triage than a generic name.
  • Validate incrementally, not just at the end: Run column-level checks with DataFrameValidator during your ETL pipeline and table-level checks with TestRunner after loading. Catching issues early prevents bad data from reaching your warehouse.
  • Separate test ownership from execution: Let data stewards define and maintain test criteria in the Collate UI. Engineers load and run those tests in pipelines using runner.run() without re-defining them in code. This keeps business logic out of pipeline scripts.
  • Confirm test definitions work before deploying: Before adding a new test to a production pipeline, run it against a known-good dataset and a known-bad dataset to confirm it passes and fails as expected.

Next Steps

Once you’ve completed advanced configuration, explore these related guides.