From 7f81c28e58c97d5568d1746508d76b7c5900c051 Mon Sep 17 00:00:00 2001 From: Teddy Date: Tue, 27 Sep 2022 17:04:23 +0200 Subject: [PATCH] Fix minor issues with dbt test results ingestion (#7744) * - Added support for test ingestion without `dbt docs generate` run - removed millisecond from timestamp - changed test result failure to 0 * Removed unused methods --- .../ingestion/source/database/dbt_source.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/ingestion/src/metadata/ingestion/source/database/dbt_source.py b/ingestion/src/metadata/ingestion/source/database/dbt_source.py index 67d816ef9bb..07b94c3ac5c 100644 --- a/ingestion/src/metadata/ingestion/source/database/dbt_source.py +++ b/ingestion/src/metadata/ingestion/source/database/dbt_source.py @@ -413,11 +413,11 @@ class DBTMixin: try: # Process the Test Status test_case_status = TestCaseStatus.Aborted - test_result_value = -1 - if dbt_test_result.get("status") == "success": + test_result_value = 0 + if dbt_test_result.get("status") in {"success", "pass"}: test_case_status = TestCaseStatus.Success test_result_value = 1 - elif dbt_test_result.get("status") == "failure": + elif dbt_test_result.get("status") in {"failure", "fail"}: test_case_status = TestCaseStatus.Failed test_result_value = 0 @@ -431,8 +431,8 @@ class DBTMixin: if dbt_test_completed_at: dbt_timestamp = datetime.strptime( dbt_test_completed_at, "%Y-%m-%dT%H:%M:%S.%fZ" - ) - dbt_timestamp = self.unix_time_millis(dbt_timestamp) + ).replace(microsecond=0) + dbt_timestamp = dbt_timestamp.timestamp() test_case_result = TestCaseResult( timestamp=dbt_timestamp, @@ -511,11 +511,3 @@ class DBTMixin: entity_link = f"<#E::table::" f"{table_fqn}>" entity_link_list.append(entity_link) return entity_link_list - - def unix_time(self, dt): - epoch = datetime.utcfromtimestamp(0) - delta = dt - epoch - return delta.total_seconds() - - def unix_time_millis(self, dt): - return int(self.unix_time(dt) * 1000)