📖 Scenario: Imagine you work in a company where many teams use data to make decisions. Sometimes, the data is confusing or wrong, and people don't trust it. To fix this, the company wants to organize how data is handled and checked. This is called data governance.
🎯 Goal: You will create a simple dbt project that shows how data governance helps keep data clean and trusted. You will set up a data source, add a rule to check data quality, and then see the results that prove the data is trustworthy.
📋 What You'll Learn
Create a source configuration for a sales table
Add a test to check that sales amounts are never negative
Write a dbt model that selects only valid sales
Run the model and show the filtered results
💡 Why This Matters
🌍 Real World
Companies use data governance to make sure data is accurate and reliable before teams use it for decisions.
💼 Career
Data analysts and engineers use dbt to build trusted data pipelines that enforce governance rules and improve data trust.
Progress0 / 4 steps
1
Set up the sales data source
Create a source configuration in sources.yml for a table called sales in the raw schema. The source name should be raw_data. Include the table name and schema exactly as given.
dbt
Hint
Use the sources key with a list containing a source named raw_data. Inside it, set schema to raw and add a table named sales.
2
Add a test to check sales amounts
In the same sources.yml file, add a test under the sales table to ensure the column amount is never negative. Use the built-in dbt test not_null and a custom test for amount >= 0.
dbt
Hint
Under the sales table, add a columns list. For the amount column, add not_null and a test with expression: amount >= 0.
3
Create a model to select valid sales
Create a dbt model file called valid_sales.sql. Write a SQL query that selects all columns from the source raw_data.sales where amount is greater than or equal to zero.
dbt
Hint
Use the source function with 'raw_data' and 'sales'. Add a where clause to keep rows with amount >= 0.
4
Run the model and show the results
Run the dbt model valid_sales and print the resulting rows. Use print() to display the output of the model query.
dbt
Hint
Print the column headers and example rows that show only sales with non-negative amounts.
Practice
(1/5)
1. Why is data governance important for building trust in data within a team?
easy
A. It removes the need for data documentation.
B. It makes data processing slower and more complex.
C. It hides data from most team members to avoid confusion.
D. It sets clear rules to keep data accurate and consistent.
Solution
Step 1: Understand the role of governance
Governance creates rules and standards to ensure data is accurate and consistent.
Step 2: Connect governance to trust
When data is accurate and consistent, teams can trust and confidently use it.
Final Answer:
It sets clear rules to keep data accurate and consistent. -> Option D
Quick Check:
Governance = Clear rules = Trust [OK]
Hint: Governance means clear rules for accurate data [OK]
Common Mistakes:
Thinking governance slows down data use
Believing governance hides data
Assuming governance removes documentation
2. Which dbt feature directly supports data governance by checking data quality?
easy
A. dbt models
B. dbt tests
C. dbt snapshots
D. dbt seeds
Solution
Step 1: Identify dbt features
dbt models build data tables, seeds load static data, snapshots track changes, tests check data quality.
Step 2: Match feature to governance
Data governance needs quality checks, which dbt tests provide by validating data correctness.
Final Answer:
dbt tests -> Option B
Quick Check:
Tests = Quality checks = Governance support [OK]
Hint: Tests check data quality to support governance [OK]
Common Mistakes:
Confusing models with tests
Thinking snapshots check quality
Assuming seeds validate data
3. Given this dbt test code snippet, what will be the result if the column user_id contains NULL values?
A. The test will fail because NULL values exist in user_id.
B. The test will pass because NULLs are allowed.
C. The test will be ignored by dbt.
D. The test will cause a syntax error.
Solution
Step 1: Understand the not_null test
This test checks that the specified column has no NULL values.
Step 2: Analyze the presence of NULLs
If user_id contains NULLs, the test will detect them and fail.
Final Answer:
The test will fail because NULL values exist in user_id. -> Option A
Quick Check:
not_null test + NULL values = Fail [OK]
Hint: not_null test fails if any NULL found [OK]
Common Mistakes:
Assuming NULLs pass not_null test
Thinking test is ignored automatically
Believing syntax error occurs
4. You wrote this dbt test to ensure no duplicate emails:
tests:
- unique:
column_name: email
But it does not run. What is the error?
medium
A. The test name should be unique without parameters.
B. The test should be written as - unique without column_name.
C. The test should be under the columns section with just - unique.
D. The test requires a SQL file, so this YAML is invalid.
Solution
Step 1: Check correct test syntax in dbt schema.yml
Tests on columns go under the columns section with just - unique listed.
Step 2: Identify the mistake
The test is incorrectly placed and uses column_name, which is not valid here.
Final Answer:
The test should be under the columns section with just - unique. -> Option C
Quick Check:
Unique test syntax = under columns with - unique [OK]
Hint: Place tests under columns with simple names [OK]
Common Mistakes:
Using parameters like column_name in schema tests
Placing tests outside columns section
Thinking SQL files are needed for built-in tests
5. Your team wants to ensure data trust by documenting all models and adding tests in dbt. Which combination best supports governance?
hard
A. Write detailed model descriptions and add tests like not_null and unique on key columns.
B. Only add tests without documentation to save time.
C. Document models but skip tests since they slow down builds.
D. Use snapshots only to track data changes without tests or docs.
Solution
Step 1: Understand governance needs
Governance requires both clear documentation and data quality checks to build trust.
Step 2: Evaluate options
Write detailed model descriptions and add tests like not_null and unique on key columns. combines documentation and tests, supporting governance best. Others skip key parts.
Final Answer:
Write detailed model descriptions and add tests like not_null and unique on key columns. -> Option A
Quick Check:
Docs + tests = Strong governance [OK]
Hint: Combine docs and tests for best governance [OK]
Common Mistakes:
Skipping docs or tests thinking one is enough
Avoiding tests to speed builds
Relying only on snapshots for trust
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.