Copilot commented on code in PR #3786:
URL: https://github.com/apache/iceberg-python/pull/3786#discussion_r3782748870


##########
pyiceberg/partitioning.py:
##########
@@ -550,3 +551,32 @@ def _(type: IcebergType, value: uuid.UUID | int | bytes | 
None) -> bytes | int |
 @_to_partition_representation.register(PrimitiveType)
 def _(type: IcebergType, value: Any | None) -> Any | None:
     return value
+
+
+def build_field_value_predicate(field_names: list[str], field_values: Record) 
-> BooleanExpression:
+    """Build a predicate matching a single record via per-field 
EqualTo/IsNull, ANDed together.
+
+    Args:
+        field_names: The name to reference for each position in field_values.
+        field_values: The values to match, one per field name, by position.
+
+    Raises:
+        IndexError: If field_names is empty.
+    """
+    predicates: list[BooleanExpression] = [
+        EqualTo(Reference(name), field_values[pos]) if field_values[pos] is 
not None else IsNull(Reference(name))
+        for pos, name in enumerate(field_names)
+    ]
+    return And(*predicates) if len(predicates) > 1 else predicates[0]

Review Comment:
   `build_field_value_predicate` implicitly raises `IndexError` when 
`field_names` is empty (and may also raise `IndexError` if `field_values` is 
shorter than `field_names`). Since this helper is now part of 
`pyiceberg.partitioning`, it would be clearer to validate inputs and raise a 
`ValueError` with a helpful message instead of relying on a cryptic indexing 
failure.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to