Source freshness checks help you know if your data is up-to-date. They tell you when the data was last updated so you can trust your reports.
Source freshness checks in dbt
Start learning this pattern below
Jump into concepts and practice - no test required
sources:
- name: your_source_name
tables:
- name: your_table_name
freshness:
warn_after:
count: 24
period: hour
error_after:
count: 48
period: hourwarn_after sets when dbt should warn you if data is too old.
error_after sets when dbt should stop the run and show an error if data is too old.
sources:
- name: sales_data
tables:
- name: sales_data
freshness:
warn_after:
count: 12
period: hour
error_after:
count: 24
period: hoursources:
- name: user_events
tables:
- name: user_events
freshness:
warn_after:
count: 1
period: day
error_after:
count: 2
period: dayThis dbt source config checks the freshness of the 'orders' table in 'my_source'. It warns if data is older than 6 hours and errors if older than 12 hours.
version: 2 sources: - name: my_source tables: - name: orders freshness: warn_after: count: 6 period: hour error_after: count: 12 period: hour
Freshness checks require your source tables to have a timestamp column that shows when data was last updated.
You can run freshness checks separately using dbt source freshness command.
Set warn_after and error_after based on how often your data updates in real life.
Source freshness checks help you track how recent your data is.
Use warn_after and error_after to set thresholds for alerts and errors.
Run freshness checks regularly to keep your data trustworthy.
Practice
Solution
Step 1: Understand the role of freshness checks
Freshness checks monitor the age of data in source tables to ensure it is up-to-date.Step 2: Compare options to the purpose
Only To track how recent the data in your source tables is describes tracking data recency, which matches the purpose of freshness checks.Final Answer:
To track how recent the data in your source tables is -> Option AQuick Check:
Freshness checks = track data recency [OK]
- Confusing freshness checks with table creation
- Thinking freshness checks optimize queries
- Assuming freshness checks schedule runs
Solution
Step 1: Recall correct YAML syntax for freshness
dbt expects warn_after and error_after as objects with count and period keys.Step 2: Match options to syntax
freshness: warn_after: {count: 1, period: day} error_after: {count: 2, period: day} correctly uses {count: X, period: day} format; others use incorrect formats or swap thresholds.Final Answer:
freshness: warn_after: {count: 1, period: day} error_after: {count: 2, period: day} -> Option BQuick Check:
Use count and period keys in YAML freshness [OK]
- Using strings instead of objects for thresholds
- Swapping warn_after and error_after values
- Missing count or period keys
{"status": "", "max_loaded_at": "2024-04-20T00:00:00Z"}Solution
Step 1: Calculate data age from last loaded timestamp
If today is 2024-04-23, data is 3 days old (2024-04-23 - 2024-04-20).Step 2: Compare data age to thresholds
3 days > error_after (2 days), so status is error.Final Answer:
error -> Option AQuick Check:
Data age > error_after = error status [OK]
- Confusing warn_after and error_after thresholds
- Assuming status is warn for data older than error_after
- Ignoring current date when calculating age
sources:
- name: my_source
freshness:
warn_after: {count: 1, period: day}
error_after: {count: 2, period: days}
What is the likely cause of the error?Solution
Step 1: Check period values in freshness YAML
dbt expects period values as singular strings like 'day', not plural 'days'.Step 2: Identify error cause
Using 'days' causes a validation error; changing to 'day' fixes it.Final Answer:
The period value 'days' should be singular 'day' -> Option DQuick Check:
Period values must be singular like 'day' [OK]
- Using plural period names
- Swapping warn_after and error_after
- Adding unnecessary quotes around numbers
Solution
Step 1: Identify correct period and count values
Period should be singular 'hour', counts are numbers without quotes.Step 2: Check warn_after and error_after order
warn_after must be less than error_after; 2 < 4 is correct.Step 3: Validate options
freshness: warn_after: {count: 2, period: hour} error_after: {count: 4, period: hour} matches correct syntax and logic; A uses strings for counts, B uses plural 'hours', D swaps thresholds.Final Answer:
freshness: warn_after: {count: 2, period: hour} error_after: {count: 4, period: hour} -> Option CQuick Check:
Use singular period and correct threshold order [OK]
- Using plural period names like 'hours'
- Putting counts as strings instead of numbers
- Swapping warn_after and error_after values
