@@ -88,9 +88,9 @@ class PathConfig(BaseModel):
8888 default = None ,
8989 description = "Partitioning scheme, only valid when type='parquet'. Currently supports 'hive'." ,
9090 )
91- filter : List [str ] = Field (
91+ filter : Union [ str , List [str ] ] = Field (
9292 default_factory = list ,
93- description = "List of regular expression patterns used to filter matching files." ,
93+ description = "List of regex pattern used to filter matching files. Must contain None or one pattern only ." ,
9494 )
9595 year_range : Optional [List [int ]] = Field (
9696 default = None ,
@@ -154,13 +154,35 @@ def validate_s3_uri(cls, v: str) -> str:
154154
155155 return v
156156
157+ @field_validator ("filter" , mode = "before" )
158+ @classmethod
159+ def extract_string_from_filter (cls , v ):
160+ # 1. Handle List input: check length and extract the string
161+ if isinstance (v , list ):
162+ if len (v ) > 1 :
163+ raise ValueError (
164+ f"Filter list must contain at most one element, got { len (v )} "
165+ )
166+ return v [0 ] if v else ""
167+
168+ # 2. Handle None/Empty
169+ if v is None :
170+ return ""
171+
172+ # 3. If it's already a string, just pass it through
173+ return v
174+
157175 @field_validator ("filter" , mode = "after" )
158- def validate_regex (cls , v ):
159- for pattern in v :
160- try :
161- re .compile (pattern )
162- except re .error as e :
163- raise ValueError (f"Invalid regex: { pattern } ({ e } )" )
176+ @classmethod
177+ def validate_regex (cls , v : str ) -> str :
178+ # Now 'v' is guaranteed to be a string
179+ if not v :
180+ return v
181+
182+ try :
183+ re .compile (v )
184+ except re .error as e :
185+ raise ValueError (f"Invalid regex: { v } ({ e } )" )
164186 return v
165187
166188 @model_validator (mode = "after" )
0 commit comments