diff --git a/CHANGELOG.md b/CHANGELOG.md index e92909a..39ba817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - In the `.quickstart.yml` file: - Adds `table_variables` for relevant sources to prevent missing sources from blocking downstream Quickstart models. - Adds `supported_vars` for Quickstart UI customization, +- 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.2.0 [PR #75](https://github.com/fivetran/dbt_github/pull/75) includes the following updates: 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 )