Skip to content

Commit

Permalink
classmethod scd_args on BaseRelation
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Oct 17, 2024
1 parent 2e5c59b commit 636e6b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 11 additions & 0 deletions dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Dict,
FrozenSet,
Iterator,
List,
Optional,
Set,
Tuple,
Expand Down Expand Up @@ -341,6 +342,16 @@ def create(
)
return cls.from_dict(kwargs)

@classmethod
def scd_args(cls: Type[Self], primary_key: Union[str, List[str]], updated_at) -> List[str]:
scd_args = []
if isinstance(primary_key, list):
scd_args.extend(primary_key)
else:
scd_args.append(primary_key)
scd_args.append(updated_at)
return scd_args

@property
def can_be_renamed(self) -> bool:
return self.type in self.renameable_relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,8 @@
({{ snapshotted_rel }}.{{ columns.dbt_valid_from }} < {{ current_rel }}.{{ updated_at }})
{%- endset %}

{% if primary_key | is_list %}
{% set scd_args = [] %}
{% for key in primary_key %}
{{ scd_args.append(key) }}
{% endfor %}
{{ scd_args.append(updated_at) }}
{% set scd_id_expr = snapshot_hash_arguments(scd_args) %}
{% else %}
{% set scd_id_expr = snapshot_hash_arguments([primary_key, updated_at]) %}
{% endif %}
{% set scd_args = api.Relation.scd_args(primary_key, updated_at) %}
{% set scd_id_expr = snapshot_hash_arguments([primary_key, updated_at]) %}

{% do return({
"unique_key": primary_key,
Expand Down

0 comments on commit 636e6b8

Please sign in to comment.