From 0eebec62db537629e40f935acb896a6dd5ad291b Mon Sep 17 00:00:00 2001 From: fivetran-catfritz <111930712+fivetran-catfritz@users.noreply.github.com> Date: Tue, 28 Oct 2025 12:00:33 -0500 Subject: [PATCH] patch/partition-by-source-relation --- CHANGELOG.md | 5 +++++ dbt_project.yml | 2 +- integration_tests/dbt_project.yml | 2 +- macros/union/partition_by_source_relation.sql | 15 +++++++++++++++ .../int_github__issue_open_length.sql | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 macros/union/partition_by_source_relation.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 496395f..b2b4219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# dbt_github v1.1.1 + +## Under the Hood +- Adds the `partition_by_source_relation` macro to improve window function partition handling and prevent conflicts when the unioned data feature is disabled. + # dbt_github v1.1.0 ## Schema/Data Change diff --git a/dbt_project.yml b/dbt_project.yml index fc350fe..3d14e83 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,6 +1,6 @@ config-version: 2 name: 'github' -version: '1.1.0' +version: '1.1.1' require-dbt-version: [">=1.3.0", "<2.0.0"] models: github: diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index e3be47f..65c9e90 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -1,5 +1,5 @@ name: 'github_integration_tests' -version: '1.1.0' +version: '1.1.1' config-version: 2 profile: 'integration_tests' vars: diff --git a/macros/union/partition_by_source_relation.sql b/macros/union/partition_by_source_relation.sql new file mode 100644 index 0000000..b233d91 --- /dev/null +++ b/macros/union/partition_by_source_relation.sql @@ -0,0 +1,15 @@ +{%- macro partition_by_source_relation(has_other_partitions='yes', alias=None) -%} + +{{ adapter.dispatch('partition_by_source_relation', 'github') () }} + +{%- endmacro %} + +{% macro default__partition_by_source_relation(has_other_partitions, alias) -%} + {% set prefix = '' if alias is none else alias ~ '.' %} + + {%- if has_other_partitions == 'no' -%} + {{ 'partition by ' ~ prefix ~ 'source_relation' if var('github_sources', [])|length > 1 }} + {%- else -%} + {{ ', ' ~ prefix ~ 'source_relation' if var('github_sources', [])|length > 1 }} + {%- endif -%} +{%- endmacro -%} \ No newline at end of file diff --git a/models/intermediate/int_github__issue_open_length.sql b/models/intermediate/int_github__issue_open_length.sql index 4b77a93..05dc526 100644 --- a/models/intermediate/int_github__issue_open_length.sql +++ b/models/intermediate/int_github__issue_open_length.sql @@ -29,7 +29,7 @@ close_events_with_timestamps as ( source_relation, issue_id, updated_at as valid_starting, - coalesce(lead(updated_at) over (partition by issue_id, source_relation order by updated_at), {{ dbt.current_timestamp() }}) as valid_until, + coalesce(lead(updated_at) over (partition by issue_id {{ github.partition_by_source_relation() }} order by updated_at), {{ dbt.current_timestamp() }}) as valid_until, is_closed from close_events_stacked )