-
Notifications
You must be signed in to change notification settings - Fork 163
Add Source Freshness Results #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dpguthrie
wants to merge
34
commits into
brooklyn-data:main
Choose a base branch
from
dpguthrie:feat/add-source-freshness
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
4c79422
Add SQL for source freshness results
dpguthrie b07abca
Include source_executions when looping through
dpguthrie 7270396
Fix for wrong macro name
dpguthrie 23769ed
Add column names for source executions
dpguthrie baac8a5
Fix error passing in old argument name
dpguthrie a583226
Add flag to integration test project
dpguthrie 24b5272
Oof
dpguthrie 114e772
Count values shouldn't be strings
dpguthrie c93bbfa
Fix attributes not on node
dpguthrie bf5312e
Copy/paste fun
dpguthrie 43285e2
Missing comma
dpguthrie 5240631
Add missing comma
dpguthrie 68b1288
Add source executions model and yml
dpguthrie 8f7a167
Add missing docs blocks for new source_executions model/yml
dpguthrie 9f115e7
Add staging model for source executions
dpguthrie 3a2b0c5
Fix id name
dpguthrie d85d62d
Add staging / fact models and yml for source executions
dpguthrie 1a511bc
Remove unnecessary doc block
dpguthrie 5b61f19
Fix ref
dpguthrie 1e28b7c
Should be a string
dpguthrie 4a330a7
Fix other adapter dml
dpguthrie 53f49f4
Remove full refresh column from 'source'
dpguthrie df041c6
Add source freshness command to testing suite
dpguthrie b00dfab
Update README for instructions for opting in
dpguthrie ba03537
Merge branch 'main' into feat/add-source-freshness
michelley-an 35dc474
Take config from profiles.yml and put in dbt_project.yml
dpguthrie 549b417
Merge branch 'main' into feat/add-source-freshness
llifoawing f5848bc
Update freshness seed
llifoawing 3649492
Update source freshness checks
llifoawing 8d8d5ca
Add Snowflake none handling for freshness configs
llifoawing e840173
Merge branch 'main' into feat/add-source-freshness
llifoawing c72163a
Add macro for reserved words
llifoawing 8f7f18d
Remove quote macro
llifoawing 380cf1f
Add quoting logic for sqlserver
llifoawing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ id,load_timestamp | |
| 102,2025-04-09 12:05:00 | ||
| 103,2025-04-09 12:10:00 | ||
| 104,2025-04-09 12:15:00 | ||
| 105,2025-05-25 12:30:00 | ||
209 changes: 209 additions & 0 deletions
209
macros/upload_individual_datasets/upload_source_executions.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| {% macro upload_source_executions(sources) %} | ||
| {{ return(adapter.dispatch('get_source_executions_dml_sql', 'dbt_artifacts')(sources)) }} | ||
| {% endmacro %} | ||
|
|
||
| {% macro default__get_source_executions_dml_sql(sources) -%} | ||
| {% if sources != [] %} | ||
|
|
||
| {% set source_execution_values %} | ||
| select | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(1) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(2) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(3) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(4) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(5) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(6) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(7) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(8) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(9) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(10) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(11) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(12) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(13) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(14) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(15) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(16) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(17) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(18) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(19) }}, | ||
| {{ adapter.dispatch('parse_json', 'dbt_artifacts')(adapter.dispatch('column_identifier', 'dbt_artifacts')(20)) }} | ||
| from values | ||
| {% for source in sources -%} | ||
| ( | ||
| '{{ invocation_id }}', {# command_invocation_id #} | ||
| '{{ source.node.unique_id }}', {# node_id #} | ||
| '{{ run_started_at }}', {# run_started_at #} | ||
| '{{ source.thread_id }}', {# thread_id #} | ||
| '{{ source.status }}', {# status #} | ||
|
|
||
| {% set compile_started_at = (source.timing | selectattr("name", "eq", "compile") | first | default({}))["started_at"] %} | ||
| {% if compile_started_at %}'{{ compile_started_at }}'{% else %}null{% endif %}, {# compile_started_at #} | ||
| {% set query_completed_at = (source.timing | selectattr("name", "eq", "execute") | first | default({}))["completed_at"] %} | ||
| {% if query_completed_at %}'{{ query_completed_at }}'{% else %}null{% endif %}, {# query_completed_at #} | ||
|
|
||
| {{ source.execution_time }}, {# total_node_runtime #} | ||
| '{{ source.node.schema }}', {# schema #} | ||
| '{{ source.node.name }}', {# name #} | ||
| '{{ source.node.source_name }}', {# source_name #} | ||
| '{{ source.node.loaded_at_field }}', {# loaded_at_field #} | ||
| {% if source.node.freshness.warn_after.count is not none %}{{ source.node.freshness.warn_after.count }}{% else %}null{% endif %}, {# warn_after_count #} | ||
| {% if source.node.freshness.warn_after.period is not none %}'{{ source.node.freshness.warn_after.period }}'{% else %}null{% endif %}, {# warn_after_period #} | ||
| {% if source.node.freshness.error_after.count is not none %}{{ source.node.freshness.error_after.count }}{% else %}null{% endif %}, {# error_after_count #} | ||
| {% if source.node.freshness.error_after.period is not none %}'{{ source.node.freshness.error_after.period }}'{% else %}null{% endif %}, {# error_after_period #} | ||
| '{{ source.max_loaded_at }}', {# max_loaded_at #} | ||
| '{{ source.snapshotted_at }}', {# snapshotted_at #} | ||
| {{ source.age }}, {# age #} | ||
| '{{ tojson(source.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} | ||
| ) | ||
| {%- if not loop.last %},{%- endif %} | ||
| {% endfor %} | ||
| {% endset %} | ||
| {{ source_execution_values }} | ||
| {% else %} | ||
| {{ return ("") }} | ||
| {% endif %} | ||
| {% endmacro -%} | ||
|
|
||
|
|
||
| {% macro bigquery__get_source_executions_dml_sql(sources) -%} | ||
| {% if sources != [] %} | ||
|
|
||
| {% set source_execution_values %} | ||
| {% for source in sources -%} | ||
| ( | ||
| '{{ invocation_id }}', {# command_invocation_id #} | ||
| '{{ source.node.unique_id }}', {# node_id #} | ||
| '{{ run_started_at }}', {# run_started_at #} | ||
| '{{ source.thread_id }}', {# thread_id #} | ||
| '{{ source.status }}', {# status #} | ||
|
|
||
| {% set compile_started_at = (source.timing | selectattr("name", "eq", "compile") | first | default({}))["started_at"] %} | ||
| {% if compile_started_at %}'{{ compile_started_at }}'{% else %}null{% endif %}, {# compile_started_at #} | ||
| {% set query_completed_at = (source.timing | selectattr("name", "eq", "execute") | first | default({}))["completed_at"] %} | ||
| {% if query_completed_at %}'{{ query_completed_at }}'{% else %}null{% endif %}, {# query_completed_at #} | ||
|
|
||
| {{ source.execution_time }}, {# total_node_runtime #} | ||
| '{{ source.node.schema }}', {# schema #} | ||
| '{{ source.node.name }}', {# name #} | ||
| '{{ source.node.source_name }}', {# source_name #} | ||
| '{{ source.node.loaded_at_field }}', {# loaded_at_field #} | ||
| '{{ source.node.freshness.warn_after.count }}', {# warn_after_count #} | ||
| '{{ source.node.freshness.warn_after.period }}', {# warn_after_period #} | ||
| '{{ source.node.freshness.error_after.count }}', {# error_after_count #} | ||
| '{{ source.node.freshness.error_after.period }}', {# error_after_period #} | ||
| '{{ source.max_loaded_at }}', {# max_loaded_at #} | ||
| '{{ source.snapshotted_at }}', {# snapshotted_at #} | ||
| {{ source.age }}, {# age #} | ||
| {{ adapter.dispatch('parse_json', 'dbt_artifacts')(tojson(model.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"')) }} {# adapter_response #} | ||
| ) | ||
| {%- if not loop.last %},{%- endif %} | ||
| {% endfor %} | ||
| {% endset %} | ||
| {{ source_execution_values }} | ||
| {% else %} | ||
| {{ return ("") }} | ||
| {% endif %} | ||
| {% endmacro -%} | ||
|
|
||
|
|
||
| {% macro snowflake__get_source_executions_dml_sql(sources) -%} | ||
| {% if sources != [] %} | ||
|
|
||
| {% set source_execution_values %} | ||
| select | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(1) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(2) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(3) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(4) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(5) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(6) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(7) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(8) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(9) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(10) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(11) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(12) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(13) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(14) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(15) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(16) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(17) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(18) }}, | ||
| {{ adapter.dispatch('column_identifier', 'dbt_artifacts')(19) }}, | ||
| {{ adapter.dispatch('parse_json', 'dbt_artifacts')(adapter.dispatch('column_identifier', 'dbt_artifacts')(20)) }} | ||
| from values | ||
| {% for source in sources -%} | ||
| ( | ||
| '{{ invocation_id }}', {# command_invocation_id #} | ||
| '{{ source.node.unique_id }}', {# node_id #} | ||
| '{{ run_started_at }}', {# run_started_at #} | ||
| '{{ source.thread_id }}', {# thread_id #} | ||
| '{{ source.status }}', {# status #} | ||
|
|
||
| {% set compile_started_at = (source.timing | selectattr("name", "eq", "compile") | first | default({}))["started_at"] %} | ||
| {% if compile_started_at %}'{{ compile_started_at }}'{% else %}null{% endif %}, {# compile_started_at #} | ||
| {% set query_completed_at = (source.timing | selectattr("name", "eq", "execute") | first | default({}))["completed_at"] %} | ||
| {% if query_completed_at %}'{{ query_completed_at }}'{% else %}null{% endif %}, {# query_completed_at #} | ||
|
|
||
| {{ source.execution_time }}, {# total_node_runtime #} | ||
| '{{ source.node.schema }}', {# schema #} | ||
| '{{ source.node.name }}', {# name #} | ||
| '{{ source.node.source_name }}', {# source_name #} | ||
| '{{ source.node.loaded_at_field }}', {# loaded_at_field #} | ||
| {% if source.node.freshness.warn_after.count is not none %}{{ source.node.freshness.warn_after.count }}{% else %}null{% endif %}, {# warn_after_count #} | ||
| {% if source.node.freshness.warn_after.period is not none %}'{{ source.node.freshness.warn_after.period }}'{% else %}null{% endif %}, {# warn_after_period #} | ||
| {% if source.node.freshness.error_after.count is not none %}{{ source.node.freshness.error_after.count }}{% else %}null{% endif %}, {# error_after_count #} | ||
| {% if source.node.freshness.error_after.period is not none %}'{{ source.node.freshness.error_after.period }}'{% else %}null{% endif %}, {# error_after_period #} | ||
| '{{ source.max_loaded_at }}', {# max_loaded_at #} | ||
| '{{ source.snapshotted_at }}', {# snapshotted_at #} | ||
| {{ source.age }}, {# age #} | ||
| '{{ tojson(source.adapter_response) | replace("\\", "\\\\") | replace("'", "\\'") | replace('"', '\\"') }}' {# adapter_response #} | ||
| ) | ||
| {%- if not loop.last %},{%- endif %} | ||
| {% endfor %} | ||
| {% endset %} | ||
| {{ source_execution_values }} | ||
| {% else %} | ||
| {{ return ("") }} | ||
| {% endif %} | ||
| {% endmacro -%} | ||
|
|
||
| {% macro postgres__get_source_executions_dml_sql(sources) -%} | ||
| {% if sources != [] %} | ||
|
|
||
| {% set source_execution_values %} | ||
| {% for source in sources -%} | ||
| ( | ||
| '{{ invocation_id }}', {# command_invocation_id #} | ||
| '{{ source.node.unique_id }}', {# node_id #} | ||
| '{{ run_started_at }}', {# run_started_at #} | ||
| '{{ source.thread_id }}', {# thread_id #} | ||
| '{{ source.status }}', {# status #} | ||
|
|
||
| {% set compile_started_at = (source.timing | selectattr("name", "eq", "compile") | first | default({}))["started_at"] %} | ||
| {% if compile_started_at %}'{{ compile_started_at }}'{% else %}null{% endif %}, {# compile_started_at #} | ||
| {% set query_completed_at = (source.timing | selectattr("name", "eq", "execute") | first | default({}))["completed_at"] %} | ||
| {% if query_completed_at %}'{{ query_completed_at }}'{% else %}null{% endif %}, {# query_completed_at #} | ||
|
|
||
| {{ source.execution_time }}, {# total_node_runtime #} | ||
| '{{ source.node.schema }}', {# schema #} | ||
| '{{ source.node.name }}', {# name #} | ||
| '{{ source.node.source_name }}', {# source_name #} | ||
| '{{ source.node.loaded_at_field }}', {# loaded_at_field #} | ||
| '{{ source.node.freshness.warn_after.count }}', {# warn_after_count #} | ||
| '{{ source.node.freshness.warn_after.period }}', {# warn_after_period #} | ||
| '{{ source.node.freshness.error_after.count }}', {# error_after_count #} | ||
| '{{ source.node.freshness.error_after.period }}', {# error_after_period #} | ||
| '{{ source.max_loaded_at }}', {# max_loaded_at #} | ||
| '{{ source.snapshotted_at }}', {# snapshotted_at #} | ||
| {{ source.age }}, {# age #} | ||
| $${{ tojson(model.adapter_response) }}$$ {# adapter_response #} | ||
| ) | ||
| {%- if not loop.last %},{%- endif %} | ||
| {% endfor %} | ||
| {% endset %} | ||
| {{ source_execution_values }} | ||
| {% else %} | ||
| {{ return ("") }} | ||
| {% endif %} | ||
| {% endmacro -%} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.