Generic tests with parameters
📖 Scenario: You are working on a data warehouse project using dbt. You want to ensure data quality by creating generic tests that can be reused with different parameters on various tables and columns.
🎯 Goal: Build a reusable generic test in dbt that accepts parameters for table name, column name, and a threshold value, then apply this test to check if the number of null values in a column exceeds the threshold.
📋 What You'll Learn
Create a generic test SQL file that accepts parameters:
model, column_name, and max_nullsWrite a SQL query inside the test that counts nulls in the specified column of the specified model
Fail the test if the count of nulls is greater than
max_nullsConfigure the test in
schema.yml with parameters for a specific model and columnRun the test and output the result
💡 Why This Matters
🌍 Real World
Data teams use generic tests in dbt to enforce data quality rules consistently across many tables and columns without rewriting SQL for each case.
💼 Career
Knowing how to write and configure generic tests with parameters is essential for data engineers and analysts working with dbt to maintain reliable data pipelines.
Progress0 / 4 steps