Skip to content

Commit

Permalink
Allow to use a costum field as check-cols updated_at (#3376)
Browse files Browse the repository at this point in the history
* Allow to use a costum field as check-cols updated_at

* Clarify changlog /w jtcohen6
  • Loading branch information
PJGaetan authored May 21, 2021
1 parent e775f2b commit 7418f36
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## dbt 0.20.0 (Release TBD)

### Features
- Support optional `updated_at` config parameter with `check` strategy snapshots. If not supplied, will use current timestamp (default). ([#1844](https:/fishtown-analytics/dbt/issues/1844), [#3376](https:/fishtown-analytics/dbt/pull/3376))

### Fixes
- Fix compiled sql for ephemeral models ([#3317](https:/fishtown-analytics/dbt/issues/3317), [#3318](https:/fishtown-analytics/dbt/pull/3318))
- Now generating `run_results.json` even when no nodes are selected ([#3313](https:/fishtown-analytics/dbt/issues/3313), [#3315](https:/fishtown-analytics/dbt/pull/3315))
Expand All @@ -23,6 +26,7 @@ Contributors:
- [@elikastelein](https:/elikastelein) ([#3149](https:/fishtown-analytics/dbt/pull/3149))
- [@majidaldo](https:/majidaldo) ([#3134](https:/fishtown-analytics/dbt/issues/3134))
- [@jaypeedevlin](https:/jaypeedevlin) ([#2999](https:/fishtown-analytics/dbt/issues/2999))
- [@PJGaetan](https:/PJGaetan) ([#3315](https:/fishtown-analytics/dbt/pull/3376))

## dbt 0.20.0b1 (May 03, 2021)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
{% if now is none or now is undefined -%}
{%- do exceptions.raise_compiler_error('Could not get a snapshot start time from the database') -%}
{%- endif %}
{% set updated_at = snapshot_string_as_time(now) %}
{% set updated_at = config.get('updated_at', snapshot_string_as_time(now)) %}

{% set column_added = false %}

Expand Down
47 changes: 47 additions & 0 deletions test/integration/004_simple_snapshot_test/test_simple_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,53 @@ def project_config(self):
}


class TestUpdatedAtCheckCols(TestCheckCols):
def _assertTablesEqualSql(self, relation_a, relation_b, columns=None):
revived_records = self.run_sql(
'''
select
id,
updated_at,
dbt_valid_from
from {}
'''.format(relation_b),
fetch='all'
)

for result in revived_records:
# result is a tuple, the updated_at is second and dbt_valid_from is latest
self.assertIsInstance(result[1], datetime)
self.assertIsInstance(result[2], datetime)
self.assertEqual(result[1].replace(tzinfo=pytz.UTC), result[2].replace(tzinfo=pytz.UTC))

if columns is None:
columns = [c for c in self.get_relation_columns(relation_a) if not c[0].lower().startswith('dbt_')]
return super()._assertTablesEqualSql(relation_a, relation_b, columns=columns)

def assert_expected(self):
super().assert_expected()
self.assertTablesEqual('snapshot_checkall', 'snapshot_expected')


@property
def project_config(self):
return {
'config-version': 2,
"data-paths": ['data'],
"snapshot-paths": ['test-check-col-snapshots-noconfig'],
"snapshots": {
"test": {
"target_schema": self.unique_schema(),
"unique_key": "id || '-' || first_name",
"strategy": "check",
"check_cols" : "all",
"updated_at": "updated_at",
},
},
'macro-paths': ['macros'],
}


class TestCheckColsBigquery(TestSimpleSnapshotFilesBigquery):
def _assertTablesEqualSql(self, relation_a, relation_b, columns=None):
# When building the equality tests, only test columns that don't start
Expand Down

0 comments on commit 7418f36

Please sign in to comment.