Skip to content

Commit

Permalink
Merge pull request #296 from dbt-labs/fix/issue-ducplicates-v4
Browse files Browse the repository at this point in the history
🐛 Fix for duplicate PKs in stg relationships
  • Loading branch information
dave-connors-3 authored Feb 1, 2023
2 parents a955400 + 54d2ade commit 8a4c7e4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions integration_tests/models/marts/exposures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ exposures:
depends_on:
- ref('fct_model_6')
- ref('dim_model_7')
- ref('dim_model_7')
- source('source_1', 'table_1')
2 changes: 2 additions & 0 deletions integration_tests/models/marts/int_model_4.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
-- depends on: {{ ref('stg_model_1') }}
-- depends on: {{ ref('stg_model_1') }}
-- depends on: {{ ref('stg_model_1') }}
-- depends on: {{ source('source_1', 'table_2') }}

select 1 as id
2 changes: 1 addition & 1 deletion macros/unpack/get_relationship_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
[
"cast('" ~ node.unique_id ~ "' as " ~ dbt.type_string() ~ ")",
"cast('" ~ parent ~ "' as " ~ dbt.type_string() ~ ")",
"" ~ loop.last ~ ""
"" ~ loop.last ~ "" if node.unique_id.split('.')[0] == 'test' else "FALSE"
]
%}

Expand Down
2 changes: 1 addition & 1 deletion models/staging/graph/stg_metric_relationships.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ final as (
from _base_metric_relationships
)

select * from final
select distinct * from final
3 changes: 2 additions & 1 deletion models/staging/graph/stg_node_relationships.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ final as (
from _base_node_relationships
)

select * from final
-- we need distinct as the graph lists relationships multiple times if they are ref'd multiple times
select distinct * from final

0 comments on commit 8a4c7e4

Please sign in to comment.