Skip to content

Commit

Permalink
Adding the defaultDataSourceProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
tombaeyens committed Feb 13, 2025
1 parent 23a6af4 commit 7c2c95e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions soda-core/src/soda_core/common/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from soda_core.common.statements.metadata_columns_query import MetadataColumnsQuery, ColumnMetadata
from soda_core.common.statements.metadata_tables_query import MetadataTablesQuery
from soda_core.common.yaml import YamlSource, YamlFileContent
from soda_core.contracts.contract_verification import DataSourceInfo


class DataSource(ABC):
Expand Down Expand Up @@ -165,3 +166,9 @@ def test_connection_error_message(self) -> Optional[str]:
return None
except Exception as e:
return str(e)

def build_data_source_info(self) -> DataSourceInfo:
return DataSourceInfo(
name=self.name,
type=self.type_name
)
4 changes: 3 additions & 1 deletion soda-core/src/soda_core/common/soda_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def build_contract_result_json(self, contract_result: ContractResult) -> dict:
{
"definitionName": contract_result.soda_qualified_dataset_name,
"defaultDataSource": contract_result.data_source_name,
"defaultDataSourceProperties": {
"type": contract_result.data_source_info.type
},
# dataTimestamp can be changed by user, this is shown in Cloud as time of a scan.
# It's the timestamp used to identify the time partition, which is the slice of data that is verified.
"dataTimestamp": contract_result.data_timestamp,
Expand All @@ -175,7 +178,6 @@ def build_contract_result_json(self, contract_result: ContractResult) -> dict:
# ],
"logs": log_cloud_json_dicts,
"sourceOwner": "soda-core",

"contract": {
"fileId": contract_result.contract_info.source.soda_cloud_file_id,
"dataset": {
Expand Down
11 changes: 10 additions & 1 deletion soda-core/src/soda_core/contracts/contract_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ class ContractInfo:
source: YamlFileContentInfo


@dataclass
class DataSourceInfo:
name: str
type: str


@dataclass
class ThresholdInfo:
must_be_greater_than: Number | None = None
Expand Down Expand Up @@ -274,6 +280,7 @@ class ContractResult:
def __init__(
self,
contract_info: ContractInfo,
data_source_info: DataSourceInfo,
data_timestamp: datetime | None,
started_timestamp: datetime,
ended_timestamp: datetime,
Expand All @@ -285,13 +292,15 @@ def __init__(
logs: Logs
):
self.contract_info: ContractInfo = contract_info
# TODO move to contract info
# TODO move to contract info or use the data_source_info
self.data_source_name: str = data_source_name
# TODO move to contract info
self.soda_qualified_dataset_name: str = soda_qualified_dataset_name
# TODO move to contract info
self.sql_qualified_dataset_name: str = sql_qualified_dataset_name

self.data_source_info: DataSourceInfo = data_source_info

self.data_timestamp: datetime | None = data_timestamp
self.started_timestamp: datetime = started_timestamp
self.ended_timestamp: datetime = ended_timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from soda_core.common.sql_dialect import *
from soda_core.common.yaml import YamlSource, VariableResolver, YamlFileContent
from soda_core.contracts.contract_verification import ContractVerificationResult, ContractResult, \
CheckResult, Measurement, ThresholdInfo, ContractInfo, CheckInfo, YamlFileContentInfo
CheckResult, Measurement, ThresholdInfo, ContractInfo, CheckInfo, YamlFileContentInfo, DataSourceInfo
from soda_core.contracts.impl.contract_yaml import ContractYaml, CheckYaml, ColumnYaml, RangeYaml, \
MissingAndValidityYaml, ValidReferenceDataYaml, MissingAncValidityCheckYaml, ThresholdCheckYaml

Expand Down Expand Up @@ -327,6 +327,7 @@ def verify(self) -> ContractResult:
measurements.append(derived_measurement)

contract_info: ContractInfo = self.build_contract_info()
data_source_info: DataSourceInfo = self.data_source.build_data_source_info()

# Evaluate the checks
measurement_values = MeasurementValues(measurements)
Expand All @@ -340,6 +341,7 @@ def verify(self) -> ContractResult:

return ContractResult(
contract_info=contract_info,
data_source_info=data_source_info,
data_timestamp=self.data_timestamp,
started_timestamp=self.started_timestamp,
ended_timestamp=datetime.now(tz=timezone.utc),
Expand Down

0 comments on commit 7c2c95e

Please sign in to comment.