Skip to content

Commit 5a1c940

Browse files
authored
Dataset CTE: fix invalid ref check (#2485)
1 parent 6feaf34 commit 5a1c940

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

soda-core/src/soda_core/contracts/impl/check_types/invalidity_check.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,15 @@ def __init__(
213213
self.sampler_type: Optional[str] = sampler_type
214214
self.sampler_limit: Optional[Number] = sampler_limit
215215

216-
sql_ast = self.build_query(cte=cte)
216+
self._cte = cte
217+
218+
sql_ast = self.build_query(cte=self._cte, select_clause=SELECT(COUNT(STAR())))
217219
self.sql = self.data_source_impl.sql_dialect.build_select_sql(sql_ast)
218220

219-
def build_query(self, cte: CTE) -> list[SqlExpression]:
221+
def build_query(self, cte: CTE, select_clause: SqlExpression) -> list[SqlExpression]:
220222
query = [
221223
WITH([cte, self.referenced_cte()]),
222-
SELECT(COUNT(STAR())),
224+
select_clause,
223225
FROM(cte.alias).AS(self.referencing_alias),
224226
WHERE.optional(SqlExpressionStr.optional(self.check_filter)),
225227
]

soda-tests/src/helpers/data_source_test_helper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,13 +525,15 @@ def assert_contract_fail(
525525
variables: Optional[dict[str, str]] = None,
526526
dwh_data_source_file_path: Optional[str] = None,
527527
extra_data_source_impls: list[DataSourceImpl] = [],
528+
publish_results: bool = True,
528529
) -> ContractVerificationResult:
529530
contract_verification_session_result: ContractVerificationSessionResult = self.verify_contract(
530531
contract_yaml_str=contract_yaml_str,
531532
test_table=test_table,
532533
variables=variables,
533534
dwh_data_source_file_path=dwh_data_source_file_path,
534535
extra_data_source_impls=extra_data_source_impls,
536+
publish_results=publish_results,
535537
)
536538
if contract_verification_session_result.is_ok:
537539
raise AssertionError(f"Expected contract verification failed")
@@ -544,13 +546,15 @@ def assert_contract_warn(
544546
variables: Optional[dict[str, str]] = None,
545547
dwh_data_source_file_path: Optional[str] = None,
546548
extra_data_source_impls: list[DataSourceImpl] = [],
549+
publish_results: bool = True,
547550
) -> ContractVerificationResult:
548551
contract_verification_session_result: ContractVerificationSessionResult = self.verify_contract(
549552
contract_yaml_str=contract_yaml_str,
550553
test_table=test_table,
551554
variables=variables,
552555
dwh_data_source_file_path=dwh_data_source_file_path,
553556
extra_data_source_impls=extra_data_source_impls,
557+
publish_results=publish_results,
554558
)
555559
if not contract_verification_session_result.is_warned:
556560
raise AssertionError(f"Expected contract verification warned")

0 commit comments

Comments
 (0)