moomindani commented on code in PR #3630:
URL: https://github.com/apache/iceberg-python/pull/3630#discussion_r3562617906
##########
pyiceberg/partitioning.py:
##########
@@ -115,13 +117,36 @@ def map_source_ids_onto_source_id(cls, data: Any) -> Any:
if len(source_ids) == 0:
raise ValueError("Empty source-ids is not allowed")
if len(source_ids) > 1:
- raise ValueError("Multi argument transforms are not
yet supported")
+ if data.get("transform") is None:
+ raise ValueError("Transform is required for a
multi-argument field")
+ # Multi-argument transforms cannot be evaluated; per
the spec, v3 readers
+ # must read tables with such transforms, ignoring them
+ data["transform"] =
UnknownTransform(transform=str(data["transform"]))
+ else:
+ data.pop("source-ids", None)
data["source-id"] = source_ids[0]
return data
+ @model_serializer(mode="wrap")
+ def _serialize_source_ids(self, handler: Any) -> Any:
+ serialized = handler(self)
+ # Per the spec, single-argument transforms write only source-id and
+ # multi-argument transforms write only source-ids
+ if self.source_ids is not None and len(self.source_ids) > 1:
+ serialized.pop("source-id", None)
+ serialized.pop("source_id", None)
+ else:
+ serialized.pop("source-ids", None)
+ serialized.pop("source_ids", None)
+ return serialized
+
def __str__(self) -> str:
"""Return the string representation of the PartitionField class."""
- return f"{self.field_id}: {self.name}:
{self.transform}({self.source_id})"
+ if self.source_ids is not None and len(self.source_ids) > 1:
+ sources = ", ".join(str(s) for s in self.source_ids)
+ else:
+ sources = str(self.source_id)
+ return f"{self.field_id}: {self.name}: {self.transform}({sources})"
Review Comment:
Updated `SortField.__str__` in 818e6f99 to render all source ids the same
way as `PartitionField.__str__`.
--
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]