aless10 commented on code in PR #8286:
URL: https://github.com/apache/iceberg/pull/8286#discussion_r1291292807


##########
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 tried to look at what pydantic does and basically it takes the string and 
then calls json.load. So one of the thing that we can do is:
   1. move the json.load call inside this method
   2. call the parse_object: now we don't have to concatenate the string since 
the object is the correct one



-- 
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