Skip to content

Commit 9a9391e

Browse files
authored
Add max operator to get_relation_last_modified macro (#234)
### Summary Metadata freshness checks were not working properly if `dbt source freshness` was ran without using the `loaded_at_field` keyword. This is because we were not reducing the amount of results to the max commited_at value in our metadata select statement. ### Description Added the max operator as suggested by @KingLommel. Also fixed the relevant test to include more than one snapshot. ### Changelog - [x] Added a summary of what this PR accomplishes to CHANGELOG.md ### Related Issue #229
1 parent 8a295da commit 9a9391e

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# dbt-dremio MAIN
22

33
- [#223](https://github.com/dremio/dbt-dremio/issues/224) Implement merge strategy for incremental materializations
4+
- [#229](https://github.com/dremio/dbt-dremio/issues/229) Add max operator to get_relation_last_modified macro
45

56
# dbt-dremio v1.7.0
67

dbt/include/dremio/macros/adapters/metadata.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ limitations under the License.*/
312312
{%- if relation.type != 'view' -%}
313313

314314
{%- call statement('last_modified', fetch_result=True) -%}
315-
select committed_at as last_modified,
315+
select max(committed_at) as last_modified,
316316
{{ current_timestamp() }} as snapshotted_at
317317
from TABLE( table_snapshot('{{relation}}') )
318318
{%- endcall -%}

tests/functional/adapter/relation/test_get_relation_last_modified.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from dbt.tests.util import run_dbt
3-
from tests.utils.util import BUCKET
3+
from tests.utils.util import BUCKET, relation_from_name
44

55

66
freshness_via_metadata_schema_yml = """version: 2
@@ -83,7 +83,10 @@ def test_get_last_relation_modified(self, project):
8383

8484
# run command
8585
result = run_dbt(["seed"])
86-
86+
relation = relation_from_name(project.adapter, "test_source")
87+
result = project.run_sql(
88+
f"INSERT INTO {relation} VALUES (10, 'name')", fetch="one"
89+
)
8790
results = run_dbt(["source", "freshness"])
8891
assert len(results) == 1
8992
result = results[0]

0 commit comments

Comments
 (0)