Skip to content

Commit 1819347

Browse files
authored
Failed rows: fix warn/fail thresholds for fail condition (#2084)
1 parent 8a1ce04 commit 1819347

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

soda/core/soda/execution/check/user_defined_failed_rows_expression_check.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@ def __init__(
4444
def evaluate(self, metrics: Dict[str, Metric], historic_values: Dict[str, object]):
4545
self.check_value: int = metrics.get(KEY_FAILED_ROWS_COUNT).value
4646

47-
self.outcome = CheckOutcome.FAIL
48-
49-
if self.check_value > 0:
47+
# Thresholds path
48+
if self.check_cfg.fail_threshold_cfg or self.check_cfg.warn_threshold_cfg:
5049
if self.check_cfg.fail_threshold_cfg and self.check_cfg.fail_threshold_cfg.is_bad(self.check_value):
5150
self.outcome = CheckOutcome.FAIL
5251
elif self.check_cfg.warn_threshold_cfg and self.check_cfg.warn_threshold_cfg.is_bad(self.check_value):
5352
self.outcome = CheckOutcome.WARN
53+
else:
54+
self.outcome = CheckOutcome.PASS
55+
else:
56+
# Original non-threshold path
57+
if self.check_value > 0:
58+
self.outcome = CheckOutcome.FAIL
59+
else:
60+
self.outcome = CheckOutcome.PASS
61+
62+
if self.check_value > 0:
5463
# Collect failed rows
5564
failed_rows_sql = self.get_failed_rows_sql()
5665
failed_rows_query = UserDefinedFailedRowsExpressionQuery(
@@ -64,8 +73,6 @@ def evaluate(self, metrics: Dict[str, Metric], historic_values: Dict[str, object
6473
failed_rows_query.execute()
6574
if failed_rows_query.sample_ref:
6675
self.failed_rows_sample_ref = failed_rows_query.sample_ref
67-
else:
68-
self.outcome = CheckOutcome.PASS
6976

7077
def get_failed_rows_sql(self) -> str:
7178
columns = ", ".join(

soda/core/tests/data_source/test_user_defined_failed_rows_checks.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,39 @@ def test_failed_rows_query_warn_threshold_pass(data_source_fixture: DataSourceFi
290290
)
291291
scan.execute()
292292
scan.assert_check_pass()
293+
294+
295+
def test_failed_rows_condition_fail_threshold_pass(data_source_fixture: DataSourceFixture):
296+
table_name = data_source_fixture.ensure_test_table(customers_test_table)
297+
298+
scan = data_source_fixture.create_test_scan()
299+
scan.enable_mock_sampler()
300+
scan.add_sodacl_yaml_str(
301+
f"""
302+
checks for {table_name}:
303+
- failed rows:
304+
name: Customers must have cst_size
305+
fail condition: cst_size < 0
306+
fail: when > 3
307+
"""
308+
)
309+
scan.execute()
310+
scan.assert_check_pass()
311+
312+
313+
def test_failed_rows_condition_warn_threshold_pass(data_source_fixture: DataSourceFixture):
314+
table_name = data_source_fixture.ensure_test_table(customers_test_table)
315+
316+
scan = data_source_fixture.create_test_scan()
317+
scan.enable_mock_sampler()
318+
scan.add_sodacl_yaml_str(
319+
f"""
320+
checks for {table_name}:
321+
- failed rows:
322+
name: Customers must have cst_size
323+
fail condition: cst_size < 0
324+
warn: when > 3
325+
"""
326+
)
327+
scan.execute()
328+
scan.assert_check_pass()

0 commit comments

Comments
 (0)