Skip to content

Commit

Permalink
Removing soda core change
Browse files Browse the repository at this point in the history
  • Loading branch information
tombaeyens committed Jun 28, 2024
1 parent 63bceb0 commit 8784b36
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,10 @@ ATHENA_SCHEMA=***

# Create and test checks with views instead of tables
TEST_WITH_VIEWS=false

CONTRACTS_POSTGRES_HOST=***
CONTRACTS_POSTGRES_USERNAME=***
CONTRACTS_POSTGRES_PASSWORD=***
CONTRACTS_POSTGRES_DATABASE=***

ATLAN_API_KEY=***
7 changes: 0 additions & 7 deletions soda/atlan/tests/atlan/.env.example

This file was deleted.

25 changes: 13 additions & 12 deletions soda/atlan/tests/atlan/test_atlan_contract_push_plugin.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import os
from textwrap import dedent

import pytest
from dotenv import load_dotenv

from helpers.fixtures import project_root_dir
from soda.contracts.contract_verification import (
ContractVerification,
ContractVerificationResult,
)


# @pytest.mark.skip(
# "Takes too long to be part of the local development test suite & depends on Atlan & Soda Cloud services"
# )
@pytest.mark.skip(
"Takes too long to be part of the local development test suite & depends on Atlan & Soda Cloud services"
)
def test_atlan_contract_push_plugin():
this_file_dir_path = os.path.dirname(os.path.realpath(__file__))
load_dotenv(f"{this_file_dir_path}/.env", override=True)
load_dotenv(f"{project_root_dir}/.env", override=True)

data_source_yaml_str: str = dedent(
"""
name: postgres_ds
type: postgres
atlan_qualified_name: default/postgres/1718112025
connection:
host: ${CONTRACTS_POSTGRES_HOST}
database: ${CONTRACTS_POSTGRES_DATABASE}
username: ${CONTRACTS_POSTGRES_USERNAME}
password: ${CONTRACTS_POSTGRES_PASSWORD}
host: ${POSTGRES_HOST}
database: ${POSTGRES_DATABASE}
username: ${POSTGRES_USERNAME}
password: ${POSTGRES_PASSWORD}
schema: contracts
"""
)

contract_yaml_str: str = dedent(
"""
data_source: postgres_ds
database: ${CONTRACTS_POSTGRES_DATABASE}
database: ${POSTGRES_DATABASE}
schema: contracts
dataset: students
columns:
Expand All @@ -48,8 +49,8 @@ def test_atlan_contract_push_plugin():

soda_cloud_yaml_str: str = dedent(
"""
api_key_id: ${SODA_API_KEY_ID}
api_key_secret: ${SODA_API_KEY_SECRET}
api_key_id: ${DEV_SODADATA_IO_API_KEY_ID}
api_key_secret: ${DEV_SODADATA_IO_API_KEY_SECRET}
"""
)

Expand Down
15 changes: 12 additions & 3 deletions soda/contracts/soda/contracts/contract_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,24 @@ def _verify(self, contract: Contract) -> ContractResult:
scan._data_source_manager.data_sources[self.data_source.data_source_name] = sodacl_data_source

if self.soda_cloud:
parts: list[str] = [
scan_definition_name_parts: list[str] = [
self.data_source.data_source_name,
contract.database_name,
contract.schema_name,
contract.dataset_name,
]
parts_str: str = "/".join([part for part in parts if part is not None])
parts_str: str = "/".join([part for part in scan_definition_name_parts if part is not None])
scan_definition_name = f"dataset://{parts_str}"
scan.set_scan_definition_name(scan_definition_name)

prefix_parts: list[str] = [contract.database_name, contract.schema_name]
prefix = ".".join(prefix_parts)

default_data_source_properties = {
"type": "spark_df",
"prefix": prefix
}

# noinspection PyProtectedMember
scan._configuration.soda_cloud = CustomizedSodaClCloud(
host=self.soda_cloud.host,
Expand All @@ -260,7 +269,7 @@ def _verify(self, contract: Contract) -> ContractResult:
port=self.soda_cloud.port,
logs=scan_logs,
scheme=self.soda_cloud.scheme,
default_data_source_properties=sodacl_data_source.get_basic_properties(),
default_data_source_properties=default_data_source_properties,
)

if self.variables:
Expand Down
10 changes: 9 additions & 1 deletion soda/contracts/tests/contracts/other/test_spark_session_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ def test_spark_session_api():
"""
)

soda_cloud_yaml_str: str = dedent(
"""
api_key_id: ${DEV_SODADATA_IO_API_KEY_ID}
api_key_secret: ${DEV_SODADATA_IO_API_KEY_SECRET}
"""
)

try:
contract_verification_result: ContractVerificationResult = (
ContractVerification.builder()
.with_contract_yaml_str(contract_yaml_str)
.with_data_source_spark_session(spark_session=spark_session)
.with_data_source_spark_session(spark_session)
.with_soda_cloud_yaml_str(soda_cloud_yaml_str)
.execute()
.assert_ok()
)
Expand Down
6 changes: 0 additions & 6 deletions soda/core/soda/execution/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,6 @@ def is_supported_metric_name(self, metric_name: str) -> bool:
or self.get_metric_sql_aggregation_expression(metric_name, None, None) is not None
)

def get_basic_properties(self) -> dict:
return {
"type": self.type,
"prefix": f"{self.database}.{self.schema}",
}

def get_metric_sql_aggregation_expression(self, metric_name: str, metric_args: list[object] | None, expr: str):
if "min" == metric_name:
return self.expr_min(expr)
Expand Down

0 comments on commit 8784b36

Please sign in to comment.