Skip to content

Commit 3b24316

Browse files
kgpayneNiallRees
andauthored
Add dbt cloud compatibility (#38)
* Add dbt cloud compatibility * Add full refresh to CI Co-authored-by: Niall Woodward <niall@niallrees.com>
1 parent 621bda3 commit 3b24316

20 files changed

+53
-24
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
dbt run-operation create_artifact_resources
3232
dbt seed --full-refresh
3333
dbt run-operation upload_dbt_artifacts --args '{filenames: [manifest, run_results]}'
34+
dbt run --full-refresh
3435
dbt run
3536
dbt run-operation upload_dbt_artifacts --args '{filenames: [manifest, run_results]}'
3637
dbt test

docs/catalog.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/manifest.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/run_results.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

models/fct_dbt__critical_path.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ latest_id as (
1616
-- Find the latest full, incremental execution
1717

1818
select
19-
any_value(command_invocation_id) as command_invocation_id
19+
any_value(command_invocation_id) as command_invocation_id,
20+
any_value(dbt_cloud_run_id) as dbt_cloud_run_id
2021
from latest_executions
2122

2223
),
@@ -29,7 +30,9 @@ latest_models as (
2930
models.depends_on_nodes,
3031
models.model_materialization
3132
from latest_id
32-
left join models on latest_id.command_invocation_id = models.command_invocation_id
33+
left join models on
34+
latest_id.command_invocation_id = models.command_invocation_id
35+
or latest_id.dbt_cloud_run_id = models.dbt_cloud_run_id
3336

3437

3538
),

models/fct_dbt__latest_full_model_executions.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ joined as (
2727
select
2828
model_executions.*
2929
from latest_full
30-
left join model_executions on model_executions.command_invocation_id = latest_full.command_invocation_id
30+
left join model_executions on
31+
model_executions.command_invocation_id = latest_full.command_invocation_id
32+
or model_executions.dbt_cloud_run_id = latest_full.dbt_cloud_run_id
3133

3234
),
3335

@@ -36,6 +38,7 @@ fields as (
3638
select
3739
artifact_generated_at,
3840
command_invocation_id,
41+
dbt_cloud_run_id,
3942
compile_started_at,
4043
query_completed_at,
4144
total_node_runtime,

models/incremental/dim_dbt__exposures.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{{
1+
{{
22
config(
3-
materialized='incremental',
3+
materialized='incremental',
44
unique_key='manifest_model_id'
5-
)
5+
)
66
}}
77

88
with dbt_models as (
@@ -25,9 +25,10 @@ dbt_models_incremental as (
2525

2626
fields as (
2727

28-
select
28+
select
2929
t.manifest_model_id,
3030
t.command_invocation_id,
31+
t.dbt_cloud_run_id,
3132
t.artifact_generated_at,
3233
t.node_id,
3334
t.name,
@@ -36,8 +37,8 @@ fields as (
3637
t.maturity,
3738
f.value::string as output_feeds,
3839
t.package_name
39-
from dbt_models_incremental t,
40-
lateral flatten(input => depends_on_nodes) f
40+
from dbt_models_incremental as t,
41+
lateral flatten(input => depends_on_nodes) as f
4142

4243
)
4344

models/incremental/dim_dbt__models.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fields as (
2323
select
2424
manifest_model_id,
2525
command_invocation_id,
26+
dbt_cloud_run_id,
2627
artifact_generated_at,
2728
node_id,
2829
model_database,

models/incremental/dim_dbt__sources.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fields as (
2323
select
2424
manifest_source_id,
2525
command_invocation_id,
26+
dbt_cloud_run_id,
2627
artifact_generated_at,
2728
node_id,
2829
name,

models/incremental/fct_dbt__model_executions.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ model_executions_with_materialization as (
3434
models.model_schema,
3535
models.name
3636
from model_executions_incremental
37-
left join models on (
38-
model_executions_incremental.command_invocation_id = models.command_invocation_id
37+
left join models on
38+
(
39+
model_executions_incremental.command_invocation_id = models.command_invocation_id
40+
or model_executions_incremental.dbt_cloud_run_id = models.dbt_cloud_run_id
41+
)
3942
and model_executions_incremental.node_id = models.node_id
40-
)
4143

4244
),
4345

@@ -46,6 +48,7 @@ fields as (
4648
select
4749
model_execution_id,
4850
command_invocation_id,
51+
dbt_cloud_run_id,
4952
artifact_generated_at,
5053
was_full_refresh,
5154
node_id,

models/incremental/fct_dbt__run_results.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fields as (
2626
select
2727
artifact_generated_at,
2828
command_invocation_id,
29+
dbt_cloud_run_id,
2930
dbt_version,
3031
elapsed_time,
3132
execution_command,

models/incremental/fct_dbt__test_executions.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fields as (
2424
select
2525
model_execution_id,
2626
command_invocation_id,
27+
dbt_cloud_run_id,
2728
artifact_generated_at,
2829
was_full_refresh,
2930
node_id,

models/incremental/int_dbt__model_executions.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fields as (
2424
select
2525
model_execution_id,
2626
command_invocation_id,
27+
dbt_cloud_run_id,
2728
artifact_generated_at,
2829
was_full_refresh,
2930
node_id,

models/staging/stg_dbt__artifacts.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fields as (
99

1010
select
1111
data:metadata:invocation_id::string as command_invocation_id,
12+
data:metadata:env:DBT_CLOUD_RUN_ID::int as dbt_cloud_run_id,
1213
generated_at,
1314
path,
1415
artifact_type,
@@ -17,7 +18,7 @@ fields as (
1718

1819
),
1920

20-
duduped as (
21+
deduped as (
2122

2223
select
2324
*,
@@ -34,11 +35,12 @@ artifacts as (
3435

3536
select
3637
command_invocation_id,
38+
dbt_cloud_run_id,
3739
generated_at,
3840
path,
3941
artifact_type,
4042
data
41-
from duduped
43+
from deduped
4244

4345
)
4446

models/staging/stg_dbt__exposures.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ flatten as (
1717

1818
select
1919
command_invocation_id,
20+
dbt_cloud_run_id,
2021
generated_at as artifact_generated_at,
2122
node.key as node_id,
2223
node.value:name::string as name,
@@ -36,6 +37,7 @@ surrogate_key as (
3637
select
3738
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_model_id,
3839
command_invocation_id,
40+
dbt_cloud_run_id,
3941
artifact_generated_at,
4042
node_id,
4143
name,

models/staging/stg_dbt__model_executions.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ dbt_run as (
2424
fields as (
2525

2626
select
27-
data:metadata:invocation_id::string as command_invocation_id,
27+
command_invocation_id,
28+
dbt_cloud_run_id,
2829
generated_at as artifact_generated_at,
2930
coalesce(data:args:full_refresh, 'false')::boolean as was_full_refresh,
3031
result.value:unique_id::string as node_id,
@@ -36,11 +37,11 @@ fields as (
3637

3738
-- The second item in the timing array is `execute`.
3839
result.value:timing[1]:completed_at::timestamp_ntz as query_completed_at,
39-
40+
4041
-- Confusingly, this does not match the delta of the above two timestamps.
4142
-- should we calculate it instead?
4243
coalesce(result.value:execution_time::float, 0) as total_node_runtime,
43-
44+
4445
result.value:adapter_response:rows_affected::int as rows_affected
4546
from dbt_run,
4647
lateral flatten(input => data:results) as result
@@ -52,6 +53,7 @@ surrogate_key as (
5253
select
5354
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as model_execution_id,
5455
command_invocation_id,
56+
dbt_cloud_run_id,
5557
artifact_generated_at,
5658
was_full_refresh,
5759
node_id,

models/staging/stg_dbt__models.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ flatten as (
1717

1818
select
1919
command_invocation_id,
20+
dbt_cloud_run_id,
2021
generated_at as artifact_generated_at,
2122
node.key as node_id,
2223
node.value:database::string as model_database,
@@ -38,6 +39,7 @@ surrogate_key as (
3839
select
3940
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_model_id,
4041
command_invocation_id,
42+
dbt_cloud_run_id,
4143
artifact_generated_at,
4244
node_id,
4345
model_database,

models/staging/stg_dbt__run_results.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fields as (
2525

2626
select
2727
generated_at as artifact_generated_at,
28-
data:metadata:invocation_id::string as command_invocation_id,
28+
command_invocation_id,
29+
dbt_cloud_run_id,
2930
data:metadata:dbt_version::string as dbt_version,
3031
data:metadata:env as env,
3132
data:elapsed_time::float as elapsed_time,

models/staging/stg_dbt__sources.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ flatten as (
1717

1818
select
1919
command_invocation_id,
20+
dbt_cloud_run_id,
2021
generated_at as artifact_generated_at,
2122
node.key as node_id,
2223
node.value:name::string as name,
@@ -36,6 +37,7 @@ surrogate_key as (
3637
select
3738
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_source_id,
3839
command_invocation_id,
40+
dbt_cloud_run_id,
3941
artifact_generated_at,
4042
node_id,
4143
name,

models/staging/stg_dbt__test_executions.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ dbt_run as (
2424
fields as (
2525

2626
select
27-
data:metadata:invocation_id::string as command_invocation_id,
27+
command_invocation_id,
28+
dbt_cloud_run_id,
2829
generated_at as artifact_generated_at,
2930
coalesce(data:args:full_refresh, 'false')::boolean as was_full_refresh,
3031
result.value:unique_id::string as node_id,
@@ -37,11 +38,11 @@ fields as (
3738

3839
-- The second item in the timing array is `execute`.
3940
result.value:timing[1]:completed_at::timestamp_ntz as query_completed_at,
40-
41+
4142
-- Confusingly, this does not match the delta of the above two timestamps.
4243
-- should we calculate it instead?
4344
coalesce(result.value:execution_time::float, 0) as total_node_runtime,
44-
45+
4546
result.value:adapter_response:rows_affected::int as rows_affected
4647
from dbt_run,
4748
lateral flatten(input => data:results) as result
@@ -53,6 +54,7 @@ surrogate_key as (
5354
select
5455
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as model_execution_id,
5556
command_invocation_id,
57+
dbt_cloud_run_id,
5658
artifact_generated_at,
5759
was_full_refresh,
5860
node_id,

0 commit comments

Comments
 (0)