@@ -366,21 +366,19 @@ def _build_partition_predicate(
366366 Returns:
367367 A predicate matching any of the input partition records.
368368 """
369- partition_fields = [schema .find_field (field .source_id ).name for field in spec .fields ]
370-
371- expr : BooleanExpression = AlwaysFalse ()
372- for partition_record in partition_records :
373- match_partition_expression : BooleanExpression = AlwaysTrue ()
374-
375- for pos , partition_field in enumerate (partition_fields ):
376- predicate = (
377- EqualTo (Reference (partition_field ), partition_record [pos ])
378- if partition_record [pos ] is not None
379- else IsNull (Reference (partition_field ))
380- )
381- match_partition_expression = And (match_partition_expression , predicate )
382- expr = Or (expr , match_partition_expression )
383- return expr
369+ partition_fields = [schema .find_field (f .source_id ).name for f in spec .fields ]
370+ if not partition_records or not partition_fields :
371+ return AlwaysFalse ()
372+
373+ def _match (record : Record ) -> BooleanExpression :
374+ parts : list [BooleanExpression ] = [
375+ EqualTo (Reference (name ), record [pos ]) if record [pos ] is not None else IsNull (Reference (name ))
376+ for pos , name in enumerate (partition_fields )
377+ ]
378+ return And (* parts ) if len (parts ) > 1 else parts [0 ]
379+
380+ per_record = [_match (r ) for r in partition_records ]
381+ return Or (* per_record ) if len (per_record ) > 1 else per_record [0 ]
384382
385383 def _append_snapshot_producer (
386384 self , snapshot_properties : dict [str , str ], branch : str | None = MAIN_BRANCH
0 commit comments