@@ -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-
5343def _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-
9772def _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
0 commit comments