fixed dbt runresults ts (#14572)

This commit is contained in:
Onkar Ravgan 2024-01-04 12:36:23 +05:30 committed by GitHub
parent 89d35c0a4b
commit 7fdff15648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -14,6 +14,8 @@ Constants required for dbt
from enum import Enum
DBT_RUN_RESULT_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
# Based on https://schemas.getdbt.com/dbt/manifest/v7/index.html
REQUIRED_MANIFEST_KEYS = ["name", "schema", "resource_type"]

View File

@ -12,6 +12,7 @@
DBT source methods.
"""
import traceback
from datetime import datetime
from typing import Iterable, List, Optional, Union
from metadata.generated.schema.api.lineage.addLineage import AddLineageRequest
@ -59,6 +60,7 @@ from metadata.ingestion.ometa.ometa_api import OpenMetadata
from metadata.ingestion.source.database.column_type_parser import ColumnTypeParser
from metadata.ingestion.source.database.database_service import DataModelLink
from metadata.ingestion.source.database.dbt.constants import (
DBT_RUN_RESULT_DATE_FORMAT,
REQUIRED_CATALOG_KEYS,
REQUIRED_MANIFEST_KEYS,
DbtCommonEnum,
@ -857,12 +859,21 @@ class DbtSource(DbtServiceSource):
dbt_test_completed_at = dbt_test_timing.completed_at
dbt_timestamp = None
if dbt_test_completed_at:
dbt_timestamp = dbt_test_completed_at.timestamp()
dbt_timestamp = dbt_test_completed_at
elif self.context.run_results_generate_time:
dbt_timestamp = self.context.run_results_generate_time.timestamp()
dbt_timestamp = self.context.run_results_generate_time
# check if the timestamp is a str type and convert accordingly
if isinstance(dbt_timestamp, str):
dbt_timestamp = datetime.strptime(
dbt_timestamp, DBT_RUN_RESULT_DATE_FORMAT
)
# Create the test case result object
test_case_result = TestCaseResult(
timestamp=convert_timestamp_to_milliseconds(dbt_timestamp),
timestamp=convert_timestamp_to_milliseconds(
dbt_timestamp.timestamp()
),
testCaseStatus=test_case_status,
testResultValue=[
TestResultValue(