Skip to content

Commit

Permalink
Use an Artifact ID rather than a composite OR statment in several pla…
Browse files Browse the repository at this point in the history
…ces. (#81)

* Use artifact_run_id instead of an OR statement
  • Loading branch information
alanmcruickshank authored Feb 2, 2022
1 parent bad83e8 commit f124f53
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 32 deletions.
7 changes: 2 additions & 5 deletions models/dim_dbt__current_models.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ model_executions as (
-- Get the most recent comile run
latest_compile as (

select
command_invocation_id,
dbt_cloud_run_id
select artifact_run_id
from run_results
where execution_command = 'run'
order by artifact_generated_at desc
Expand All @@ -39,8 +37,7 @@ latest_models as (
from models
-- In a local deploy, the command id is sufficient, but not in cloud - that requires the cloud run id to achieve a match.
inner join latest_compile
on models.command_invocation_id = latest_compile.command_invocation_id
or models.dbt_cloud_run_id = latest_compile.dbt_cloud_run_id
on models.artifact_run_id = latest_compile.artifact_run_id

),

Expand Down
7 changes: 2 additions & 5 deletions models/fct_dbt__critical_path.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ latest_executions as (
latest_id as (
-- Find the latest full, incremental execution

select
any_value(command_invocation_id) as command_invocation_id,
any_value(dbt_cloud_run_id) as dbt_cloud_run_id
select any_value(artifact_run_id) as artifact_run_id
from latest_executions

),
Expand All @@ -31,8 +29,7 @@ latest_models as (
models.model_materialization
from latest_id
left join models on
latest_id.command_invocation_id = models.command_invocation_id
or latest_id.dbt_cloud_run_id = models.dbt_cloud_run_id
latest_id.artifact_run_id = models.artifact_run_id


),
Expand Down
4 changes: 2 additions & 2 deletions models/fct_dbt__latest_full_model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ joined as (
model_executions.*
from latest_full
left join model_executions on
model_executions.command_invocation_id = latest_full.command_invocation_id
or model_executions.dbt_cloud_run_id = latest_full.dbt_cloud_run_id
model_executions.artifact_run_id = latest_full.artifact_run_id

),

Expand All @@ -39,6 +38,7 @@ fields as (
artifact_generated_at,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
compile_started_at,
query_completed_at,
total_node_runtime,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/dim_dbt__exposures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ dbt_exposures_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
dbt_exposures.command_invocation_id = run_results.command_invocation_id
or dbt_exposures.dbt_cloud_run_id = run_results.dbt_cloud_run_id
dbt_exposures.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand All @@ -41,6 +40,7 @@ fields as (
t.manifest_exposure_id,
t.command_invocation_id,
t.dbt_cloud_run_id,
t.artifact_run_id,
t.artifact_generated_at,
t.node_id,
t.name,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/dim_dbt__models.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ dbt_models_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
dbt_models.command_invocation_id = run_results.command_invocation_id
or dbt_models.dbt_cloud_run_id = run_results.dbt_cloud_run_id
dbt_models.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand All @@ -36,6 +35,7 @@ fields as (
manifest_model_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
model_database,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/dim_dbt__seeds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ dbt_seeds_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
dbt_seeds.command_invocation_id = run_results.command_invocation_id
or dbt_seeds.dbt_cloud_run_id = run_results.dbt_cloud_run_id
dbt_seeds.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand All @@ -36,6 +35,7 @@ fields as (
manifest_seed_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
seed_database,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/dim_dbt__snapshots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ dbt_snapshots_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
dbt_snapshots.command_invocation_id = run_results.command_invocation_id
or dbt_snapshots.dbt_cloud_run_id = run_results.dbt_cloud_run_id
dbt_snapshots.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand All @@ -36,6 +35,7 @@ fields as (
manifest_snapshot_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
snapshot_database,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/dim_dbt__sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ dbt_sources_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
dbt_sources.command_invocation_id = run_results.command_invocation_id
or dbt_sources.dbt_cloud_run_id = run_results.dbt_cloud_run_id
dbt_sources.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand All @@ -36,6 +35,7 @@ fields as (
manifest_source_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
name,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/dim_dbt__tests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ dbt_tests_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
dbt_tests.command_invocation_id = run_results.command_invocation_id
or dbt_tests.dbt_cloud_run_id = run_results.dbt_cloud_run_id
dbt_tests.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand All @@ -36,6 +35,7 @@ fields as (
manifest_test_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
name,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/fct_dbt__model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ model_executions_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
model_executions.command_invocation_id = run_results.command_invocation_id
or model_executions.dbt_cloud_run_id = run_results.dbt_cloud_run_id
model_executions.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand Down Expand Up @@ -61,6 +60,7 @@ fields as (
model_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
1 change: 1 addition & 0 deletions models/incremental/fct_dbt__run_results.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fields as (
artifact_generated_at,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
dbt_version,
elapsed_time,
execution_command,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/fct_dbt__seed_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ seed_executions_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
seed_executions.command_invocation_id = run_results.command_invocation_id
or seed_executions.dbt_cloud_run_id = run_results.dbt_cloud_run_id
seed_executions.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand Down Expand Up @@ -60,6 +59,7 @@ fields as (
seed_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/fct_dbt__snapshot_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ snapshot_executions_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
snapshot_executions.command_invocation_id = run_results.command_invocation_id
or snapshot_executions.dbt_cloud_run_id = run_results.dbt_cloud_run_id
snapshot_executions.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand Down Expand Up @@ -60,6 +59,7 @@ fields as (
snapshot_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
4 changes: 2 additions & 2 deletions models/incremental/fct_dbt__test_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ test_executions_incremental as (
-- Inner join with run results to enforce consistency and avoid race conditions.
-- https://github.com/brooklyn-data/dbt_artifacts/issues/75
inner join run_results on
test_executions.command_invocation_id = run_results.command_invocation_id
or test_executions.dbt_cloud_run_id = run_results.dbt_cloud_run_id
test_executions.artifact_run_id = run_results.artifact_run_id

{% if is_incremental() %}
-- this filter will only be applied on an incremental run
Expand All @@ -37,6 +36,7 @@ fields as (
test_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
1 change: 1 addition & 0 deletions models/incremental/int_dbt__model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fields as (
model_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__artifacts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ artifacts as (
select
command_invocation_id,
dbt_cloud_run_id,
-- This ID provides a reliable ID, regardless of whether running in a local or cloud environment.
sha2_hex(coalesce(dbt_cloud_run_id::string, command_invocation_id::string), 256) as artifact_run_id,
generated_at,
path,
artifact_type,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__exposures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flatten as (
select
manifests.command_invocation_id,
manifests.dbt_cloud_run_id,
manifests.artifact_run_id,
manifests.generated_at as artifact_generated_at,
node.key as node_id,
node.value:name::string as name,
Expand All @@ -38,6 +39,7 @@ surrogate_key as (
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_exposure_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
name,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__model_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fields as (
select
dbt_run.command_invocation_id,
dbt_run.dbt_cloud_run_id,
dbt_run.artifact_run_id,
dbt_run.generated_at as artifact_generated_at,
coalesce(dbt_run.data:args:full_refresh, 'false')::boolean as was_full_refresh,
result.value:unique_id::string as node_id,
Expand Down Expand Up @@ -54,6 +55,7 @@ surrogate_key as (
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as model_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__models.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flatten as (
select
manifests.command_invocation_id,
manifests.dbt_cloud_run_id,
manifests.artifact_run_id,
manifests.generated_at as artifact_generated_at,
node.key as node_id,
node.value:database::string as model_database,
Expand All @@ -40,6 +41,7 @@ surrogate_key as (
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_model_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
model_database,
Expand Down
1 change: 1 addition & 0 deletions models/staging/stg_dbt__run_results.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fields as (
generated_at as artifact_generated_at,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
data:metadata:dbt_version::string as dbt_version,
data:metadata:env as env,
data:elapsed_time::float as elapsed_time,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__seed_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fields as (
select
dbt_run.command_invocation_id,
dbt_run.dbt_cloud_run_id,
dbt_run.artifact_run_id,
dbt_run.generated_at as artifact_generated_at,
coalesce(dbt_run.data:args:full_refresh, 'false')::boolean as was_full_refresh,
result.value:unique_id::string as node_id,
Expand Down Expand Up @@ -55,6 +56,7 @@ surrogate_key as (
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as seed_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__seeds.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flatten as (
select
manifests.command_invocation_id,
manifests.dbt_cloud_run_id,
manifests.artifact_run_id,
manifests.generated_at as artifact_generated_at,
node.key as node_id,
node.value:database::string as seed_database,
Expand All @@ -39,6 +40,7 @@ surrogate_key as (
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_seed_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
seed_database,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__snapshot_executions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fields as (
select
dbt_run.command_invocation_id,
dbt_run.dbt_cloud_run_id,
dbt_run.artifact_run_id,
dbt_run.generated_at as artifact_generated_at,
coalesce(dbt_run.data:args:full_refresh, 'false')::boolean as was_full_refresh,
result.value:unique_id::string as node_id,
Expand Down Expand Up @@ -55,6 +56,7 @@ surrogate_key as (
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as snapshot_execution_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
was_full_refresh,
node_id,
Expand Down
2 changes: 2 additions & 0 deletions models/staging/stg_dbt__snapshots.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ flatten as (
select
manifests.command_invocation_id,
manifests.dbt_cloud_run_id,
manifests.artifact_run_id,
manifests.generated_at as artifact_generated_at,
node.key as node_id,
node.value:database::string as snapshot_database,
Expand All @@ -39,6 +40,7 @@ surrogate_key as (
{{ dbt_utils.surrogate_key(['command_invocation_id', 'node_id']) }} as manifest_snapshot_id,
command_invocation_id,
dbt_cloud_run_id,
artifact_run_id,
artifact_generated_at,
node_id,
snapshot_database,
Expand Down
Loading

0 comments on commit f124f53

Please sign in to comment.