From a066c1e8bbdd54d7b8d658b1c3eb905d756606bf Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Tue, 15 Nov 2022 14:53:55 +0100 Subject: [PATCH] Include adapter_response for freshness queries --- core/dbt/adapters/base/impl.py | 6 ++++-- .../include/global_project/macros/adapters/freshness.sql | 2 +- core/dbt/task/freshness.py | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/dbt/adapters/base/impl.py b/core/dbt/adapters/base/impl.py index 33b7c45a3c4..7adff9dd4ae 100644 --- a/core/dbt/adapters/base/impl.py +++ b/core/dbt/adapters/base/impl.py @@ -1096,7 +1096,8 @@ def calculate_freshness( } # run the macro - table = self.execute_macro(FRESHNESS_MACRO_NAME, kwargs=kwargs, manifest=manifest) + result = self.execute_macro(FRESHNESS_MACRO_NAME, kwargs=kwargs, manifest=manifest) + adapter_response, table = result.response, result.table # now we have a 1-row table of the maximum `loaded_at_field` value and # the current time according to the db. if len(table) != 1 or len(table[0]) != 2: @@ -1114,11 +1115,12 @@ def calculate_freshness( snapshotted_at = _utc(table[0][1], source, loaded_at_field) age = (snapshotted_at - max_loaded_at).total_seconds() - return { + freshness = { "max_loaded_at": max_loaded_at, "snapshotted_at": snapshotted_at, "age": age, } + return adapter_response, freshness def pre_model_hook(self, config: Mapping[str, Any]) -> Any: """A hook for running some operation before the model materialization diff --git a/core/dbt/include/global_project/macros/adapters/freshness.sql b/core/dbt/include/global_project/macros/adapters/freshness.sql index 6a5bd79d1d0..f18499a2391 100644 --- a/core/dbt/include/global_project/macros/adapters/freshness.sql +++ b/core/dbt/include/global_project/macros/adapters/freshness.sql @@ -12,5 +12,5 @@ where {{ filter }} {% endif %} {% endcall %} - {{ return(load_result('collect_freshness').table) }} + {{ return(load_result('collect_freshness')) }} {% endmacro %} diff --git a/core/dbt/task/freshness.py b/core/dbt/task/freshness.py index 51944cb4508..f227fbd996a 100644 --- a/core/dbt/task/freshness.py +++ b/core/dbt/task/freshness.py @@ -105,10 +105,10 @@ def execute(self, compiled_node, manifest): ) relation = self.adapter.Relation.create_from_source(compiled_node) - # given a Source, calculate its fresnhess. + # given a Source, calculate its freshness. with self.adapter.connection_for(compiled_node): self.adapter.clear_transaction() - freshness = self.adapter.calculate_freshness( + adapter_response, freshness = self.adapter.calculate_freshness( relation, compiled_node.loaded_at_field, compiled_node.freshness.filter, @@ -124,7 +124,7 @@ def execute(self, compiled_node, manifest): timing=[], execution_time=0, message=None, - adapter_response={}, + adapter_response=adapter_response.to_dict(omit_none=True), failures=None, **freshness, )