@@ -367,20 +367,20 @@ def _build_partition_predicate(
367367 A predicate matching any of the input partition records.
368368 """
369369 partition_fields = [schema .find_field (field .source_id ).name for field in spec .fields ]
370+ if not partition_records or not partition_fields :
371+ return AlwaysFalse ()
370372
371- expr : BooleanExpression = AlwaysFalse ()
373+ per_record_exprs : list [ BooleanExpression ] = []
372374 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
375+ predicates : list [BooleanExpression ] = [
376+ EqualTo (Reference (partition_field ), partition_record [pos ])
377+ if partition_record [pos ] is not None
378+ else IsNull (Reference (partition_field ))
379+ for pos , partition_field in enumerate (partition_fields )
380+ ]
381+ per_record_exprs .append (And (* predicates ) if len (predicates ) > 1 else predicates [0 ])
382+
383+ return Or (* per_record_exprs ) if len (per_record_exprs ) > 1 else per_record_exprs [0 ]
384384
385385 def _append_snapshot_producer (
386386 self , snapshot_properties : dict [str , str ], branch : str | None = MAIN_BRANCH
0 commit comments