Creating Custom Singular Tests in dbt
📖 Scenario: You are working on a data project using dbt to ensure your data quality. You want to create a custom singular test to check that no user has a negative age in your users table.
🎯 Goal: Build a custom singular test in dbt that checks for any negative values in the age column of the users table.
📋 What You'll Learn
Create a SQL file for the custom singular test with the exact name
no_negative_age.sql.Define a SQL query that selects rows where
age < 0 from the users table.Add a test configuration variable called
model_name with the value users.Use the
model_name variable inside the SQL query to refer to the table dynamically.Print the final SQL query string to verify the test logic.
💡 Why This Matters
🌍 Real World
Data teams use custom singular tests in dbt to ensure data quality by writing specific checks tailored to their data models.
💼 Career
Knowing how to write custom tests in dbt is valuable for data analysts and engineers to maintain trustworthy data pipelines.
Progress0 / 4 steps