@@ -368,19 +368,29 @@ def _build_partition_predicate(
368368 """
369369 partition_fields = [schema .find_field (field .source_id ).name for field in spec .fields ]
370370
371- expr : BooleanExpression = AlwaysFalse ()
371+ match_partition_expressions = []
372372 for partition_record in partition_records :
373- match_partition_expression : BooleanExpression = AlwaysTrue ()
374-
375- for pos , partition_field in enumerate (partition_fields ):
376- predicate = (
373+ predicates = [
374+ (
377375 EqualTo (Reference (partition_field ), partition_record [pos ])
378376 if partition_record [pos ] is not None
379377 else IsNull (Reference (partition_field ))
380378 )
381- match_partition_expression = And (match_partition_expression , predicate )
382- expr = Or (expr , match_partition_expression )
383- return expr
379+ for pos , partition_field in enumerate (partition_fields )
380+ ]
381+
382+ if not predicates :
383+ match_partition_expressions .append (AlwaysTrue ())
384+ elif len (predicates ) == 1 :
385+ match_partition_expressions .append (predicates [0 ])
386+ else :
387+ match_partition_expressions .append (And (* predicates ))
388+
389+ if not match_partition_expressions :
390+ return AlwaysFalse ()
391+ if len (match_partition_expressions ) == 1 :
392+ return match_partition_expressions [0 ]
393+ return Or (* match_partition_expressions )
384394
385395 def _append_snapshot_producer (
386396 self , snapshot_properties : dict [str , str ], branch : str | None = MAIN_BRANCH
0 commit comments