Skip to content

Commit 171d4e1

Browse files
committed
fixed pipeline failure
1 parent acb1449 commit 171d4e1

File tree

2 files changed

+25
-28
lines changed
  • digital_land/expectations/operations
  • tests/integration/expectations/checkpoints

2 files changed

+25
-28
lines changed

digital_land/expectations/operations/csv.py

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ def _sql_string(value) -> str:
4040
return f"'{cleaned}'"
4141

4242

43-
def _normalize_condition_groups(conditions, name: str) -> list:
44-
if conditions is None:
45-
return []
46-
if isinstance(conditions, dict):
47-
return [conditions]
48-
if isinstance(conditions, list):
49-
return conditions
50-
raise ValueError(f"{name} must be a dict, list of dicts, or None")
51-
52-
5343
def _build_field_condition(field_name: str, spec) -> str:
5444
if isinstance(spec, dict):
5545
op = str(spec.get("op", spec.get("operation", ""))).strip().lower()
@@ -79,27 +69,35 @@ def _build_field_condition(field_name: str, spec) -> str:
7969
)
8070

8171

82-
def _build_condition_group(group: dict, file_columns: list) -> str:
83-
if not isinstance(group, dict) or not group:
84-
raise ValueError("Each condition group must be a non-empty dict")
85-
86-
parts = []
87-
for field_name, spec in group.items():
88-
if field_name not in file_columns:
89-
raise ValueError(
90-
f"Column '{field_name}' not found in file. Available columns: {file_columns}"
91-
)
92-
parts.append(_build_field_condition(field_name, spec))
93-
94-
return f"({' AND '.join(parts)})"
95-
96-
9772
def _build_filter_clause(filter_spec, file_columns: list, name: str) -> str:
9873
"""Build SQL clause that keeps rows matching structured conditions."""
99-
groups = _normalize_condition_groups(filter_spec, name)
74+
if filter_spec is None:
75+
groups = []
76+
elif isinstance(filter_spec, dict):
77+
groups = [filter_spec]
78+
elif isinstance(filter_spec, list):
79+
groups = filter_spec
80+
else:
81+
raise ValueError(f"{name} must be a dict, list of dicts, or None")
82+
10083
if not groups:
10184
return ""
102-
clauses = [_build_condition_group(group, file_columns) for group in groups]
85+
86+
clauses = []
87+
for group in groups:
88+
if not isinstance(group, dict) or not group:
89+
raise ValueError("Each condition group must be a non-empty dict")
90+
91+
parts = []
92+
for field_name, spec in group.items():
93+
if field_name not in file_columns:
94+
raise ValueError(
95+
f"Column '{field_name}' not found in file. Available columns: {file_columns}"
96+
)
97+
parts.append(_build_field_condition(field_name, spec))
98+
99+
clauses.append(f"({' AND '.join(parts)})")
100+
103101
return f" AND ({' OR '.join(clauses)})"
104102

105103

tests/integration/expectations/checkpoints/test_csv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import csv
2-
import json
32
import pytest
43

54
from digital_land.expectations.checkpoints.csv import CsvCheckpoint

0 commit comments

Comments
 (0)