Fokko commented on code in PR #8286:
URL: https://github.com/apache/iceberg/pull/8286#discussion_r1290368092
##########
python/pyiceberg/table/metadata.py:
##########
@@ -380,19 +383,14 @@ def new_table_metadata(
class TableMetadataUtil:
"""Helper class for parsing TableMetadata."""
- # Once this has been resolved, we can simplify this:
https://github.com/samuelcolvin/pydantic/issues/3846
- # TableMetadata = Annotated[TableMetadata, Field(alias="format-version",
discriminator="format-version")]
+ class _MetadataWrapper(IcebergBaseModel):
+ table_metadata: TableMetadata
@staticmethod
- def parse_obj(data: Dict[str, Any]) -> TableMetadata:
- if "format-version" not in data:
- raise ValidationError(f"Missing format-version in TableMetadata:
{data}")
-
- format_version = data["format-version"]
-
- if format_version == 1:
- return TableMetadataV1(**data)
- elif format_version == 2:
- return TableMetadataV2(**data)
- else:
- raise ValidationError(f"Unknown format version: {format_version}")
+ def parse_raw(data: str) -> TableMetadata:
+ try:
+ d = f'{{"table_metadata": {data}}}'
+ metadata_wrapper = TableMetadataUtil._MetadataWrapper.parse_raw(d)
Review Comment:
I see, I also looked into the discriminator to automatically deserialize
into the right version. Would be great to get it working, but it is a bit rough
it seems.
--
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]