Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
files: ^soda-[^/]+/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -17,7 +17,7 @@ repos:
- id: detect-private-key
- id: end-of-file-fixer
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
rev: v2.3.3
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports"]
Expand All @@ -29,13 +29,13 @@ repos:
# exclude: _models?\.py$
# args: [--py38-plus, --keep-runtime-typing]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 9.0.0a3
hooks:
- id: isort
additional_dependencies: [toml]
name: Sort imports using isort
- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.3.1
hooks:
- id: black
name: Run black formatter
Expand Down
8 changes: 2 additions & 6 deletions soda-core/src/soda_core/cli/handlers/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ def handle_create_data_source(data_source_file_path: str, data_source_type: str)
try:
Path(dir_name).mkdir(parents=True, exist_ok=True)
with open(data_source_file_path, "w") as text_file:
text_file.write(
dedent(
"""
text_file.write(dedent("""
type: postgres
name: postgres_ds
connection:
host: localhost
user: ${POSTGRES_USERNAME}
password: ${POSTGRES_PASSWORD}
database: your_postgres_db
"""
).strip()
)
""").strip())
soda_logger.info(f"{Emoticons.WHITE_CHECK_MARK} Created data source file '{data_source_file_path}'")
return ExitCode.OK
except Exception as exc:
Expand Down
8 changes: 2 additions & 6 deletions soda-core/src/soda_core/cli/handlers/soda_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ def handle_create_soda_cloud(soda_cloud_file_path: str) -> ExitCode:
try:
Path(dirname(soda_cloud_file_path)).mkdir(parents=True, exist_ok=True)
with open(soda_cloud_file_path, "w") as text_file:
text_file.write(
dedent(
"""
text_file.write(dedent("""
soda_cloud:
host: cloud.soda.io
api_key_id: ${SODA_CLOUD_API_KEY_ID}
api_key_secret: ${SODA_CLOUD_API_KEY_SECRET}
"""
).strip()
)
""").strip())
soda_logger.info(f"{Emoticons.WHITE_CHECK_MARK} Created Soda Cloud configuration file '{soda_cloud_file_path}'")
return ExitCode.OK
except Exception as exc:
Expand Down
22 changes: 13 additions & 9 deletions soda-core/src/soda_core/common/soda_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,12 +1457,14 @@ def _build_contract_result_json_dict(contract_verification_result: ContractVerif
# The scan definition name is still required on result ingestion to link to the contract
# and determine if we're dealing with a default or test contract.
"definitionName": _build_scan_definition_name(contract_verification_result),
"defaultDataSource": contract_verification_result.data_source.name
if contract_verification_result.data_source
else None,
"defaultDataSourceProperties": {"type": contract_verification_result.data_source.type}
if contract_verification_result.data_source
else None,
"defaultDataSource": (
contract_verification_result.data_source.name if contract_verification_result.data_source else None
),
"defaultDataSourceProperties": (
{"type": contract_verification_result.data_source.type}
if contract_verification_result.data_source
else None
),
# 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_verification_result.data_timestamp,
Expand Down Expand Up @@ -1547,9 +1549,11 @@ def _build_diagnostics_json_dict(check_result: CheckResult) -> Optional[dict]:

return {
# TODO: this default 0 value is here only because check.diagnostics.value is a required non-nullable field in the api.
"value": int(check_result.threshold_value)
if isinstance(check_result.threshold_value, bool)
else (check_result.threshold_value or 0),
"value": (
int(check_result.threshold_value)
if isinstance(check_result.threshold_value, bool)
else (check_result.threshold_value or 0)
),
"fail": _build_fail_threshold(check_result),
"v4": _build_v4_diagnostics_check_type_json_dict(check_result),
}
Expand Down
6 changes: 2 additions & 4 deletions soda-core/src/soda_core/common/sql_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ def __post_init__(self):
# Check that the select contains a distinct and has multiple fields -> give a warning
if isinstance(self.fields, list) and len(self.fields) > 1:
if any(isinstance(field, DISTINCT) for field in self.fields):
logger.warning(
"""Found DISTINCT in a SELECT statement with multiple fields.
This might have unintended consequences."""
)
logger.warning("""Found DISTINCT in a SELECT statement with multiple fields.
This might have unintended consequences.""")


@dataclass
Expand Down
9 changes: 3 additions & 6 deletions soda-core/src/soda_core/common/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,13 @@ def parse(self) -> YamlObject:
raise YamlParserException(f"YAML syntax error", str(location))


class DataSourceYamlSource(YamlSource, file_type=FileType.DATA_SOURCE):
...
class DataSourceYamlSource(YamlSource, file_type=FileType.DATA_SOURCE): ...


class SodaCloudYamlSource(YamlSource, file_type=FileType.SODA_CLOUD):
...
class SodaCloudYamlSource(YamlSource, file_type=FileType.SODA_CLOUD): ...


class ContractYamlSource(YamlSource, file_type=FileType.CONTRACT):
...
class ContractYamlSource(YamlSource, file_type=FileType.CONTRACT): ...


class YamlValue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ def execute(self) -> list[Measurement]:
logger.error(msg=f"Could not execute schema query {self.sql}: {e}", exc_info=True)
return []
try:
metadata_columns: list[
ColumnMetadata
] = self.data_source_impl.sql_dialect.build_column_metadatas_from_query_result(query_result)
metadata_columns: list[ColumnMetadata] = (
self.data_source_impl.sql_dialect.build_column_metadatas_from_query_result(query_result)
)
except Exception as e:
logger.error(f"Error building column metadata from query result: {e}")
return []
Expand Down
3 changes: 1 addition & 2 deletions soda-core/src/soda_core/contracts/impl/contract_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

class ContractYamlExtension(Protocol):
# Extend the contract YAML object. Can modify the state of the contract YAML.
def extend(self, contract_yaml: "ContractYaml") -> None:
...
def extend(self, contract_yaml: "ContractYaml") -> None: ...


class ContractYaml:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
)


class DatabricksConnectionProperties(DataSourceConnectionProperties, ABC):
...
class DatabricksConnectionProperties(DataSourceConnectionProperties, ABC): ...


class DatabricksSharedConnectionProperties(DatabricksConnectionProperties, ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ def _build_pg_columns_metadata_query(
[
COLUMN("attname", table_alias="a", field_alias="column_name"),
# Normalize data type into information_schema.columns style.
RAW_SQL(
"""CASE
RAW_SQL("""CASE
-- arrays
WHEN t.typcategory = 'A' OR t.typelem <> 0 THEN 'ARRAY'

Expand All @@ -294,57 +293,48 @@ def _build_pg_columns_metadata_query(
ELSE COALESCE(bt.typname, t.typname)
END
END AS \"data_type\"
"""
),
"""),
# Extract type parameters. All a.atttypmod are offset by 4 in Postgres
# varchar/char length (NULL otherwise)
RAW_SQL(
"""CASE
RAW_SQL("""CASE
WHEN t.typname IN ('varchar','bpchar') THEN
CASE
WHEN a.atttypmod > 4 THEN a.atttypmod - 4
ELSE NULL
END
ELSE NULL
END AS "character_maximum_length"
"""
),
"""),
# numeric precision (NULL otherwise)
RAW_SQL(
"""CASE
RAW_SQL("""CASE
WHEN t.typname = 'numeric' THEN
CASE
WHEN a.atttypmod > 4 THEN ((a.atttypmod - 4) >> 16)
ELSE NULL
END
ELSE NULL
END AS "numeric_precision"
"""
),
"""),
# numeric scale (NULL otherwise)
RAW_SQL(
"""CASE
RAW_SQL("""CASE
WHEN t.typname = 'numeric' THEN
CASE
WHEN a.atttypmod > 4 THEN ((a.atttypmod - 4) & 65535)
ELSE NULL
END
ELSE NULL
END AS "numeric_scale"
"""
),
"""),
# datetime precision (NULL otherwise)
RAW_SQL(
"""CASE
RAW_SQL("""CASE
WHEN t.typname IN ('time','timetz','timestamp','timestamptz') THEN
CASE
WHEN a.atttypmod >= 0 THEN a.atttypmod
ELSE NULL
END
ELSE NULL
END AS "datetime_precision"
"""
),
"""),
COLUMN(current_database_expression, field_alias="table_catalog"),
COLUMN("nspname", table_alias="n", field_alias="table_schema"),
COLUMN("relname", table_alias="c", field_alias="table_name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
USER_DESCRIPTION = "Username for authentication"


class SnowflakeConnectionProperties(DataSourceConnectionProperties, ABC):
...
class SnowflakeConnectionProperties(DataSourceConnectionProperties, ABC): ...


class SnowflakeSharedConnectionProperties(SnowflakeConnectionProperties, ABC):
Expand Down
2 changes: 1 addition & 1 deletion soda-snowflake/tests/data_sources/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
# TestConnection( # connect using external browser. commented out by default because CI will hang. Uncomment to test locally
# test_name="external_browser_connection",
# connection_yaml_str=f"""
# type: snowflake
# type: snowflake
# name: SNOWFLAKE_TEST
# connection:
# account: '{SNOWFLAKE_ACCOUNT}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ def create_schema_if_not_exists_sql(self, prefixes: list[str], add_semicolon: bo
FROM sys.schemas
WHERE name = N'{schema_name}' )
EXEC('CREATE SCHEMA [{schema_name}]')
""" + (
";" if add_semicolon else ""
)
""" + (";" if add_semicolon else "")

def build_drop_table_sql(self, drop_table: DROP_TABLE | DROP_TABLE_IF_EXISTS, add_semicolon: bool = True) -> str:
if_exists_sql: str = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Common fields (name, filter, threshold, metric, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_check_from_contract


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Common fields (name, filter, threshold, metric, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_check_from_contract, parse_column_check


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
Common fields (name, filter, threshold, metric, store_failed_rows) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_check_from_contract


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
Common fields (name, filter, threshold, metric, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_check_from_contract


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
Common fields (name, filter, threshold, metric, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_column_check


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
Common fields (name, filter, threshold, metric, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_check_from_contract


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Common fields (name, filter, threshold, metric, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_column_check


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Common fields (name, filter, threshold, metric, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_check_from_contract


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Common fields (name, qualifier, filter, attributes) are tested in test_common_check_yaml_features.py.
"""


from helpers.yaml_parsing_helpers import parse_check_from_contract


Expand Down
Loading
Loading