amogh-jahagirdar commented on code in PR #411:
URL: https://github.com/apache/iceberg-python/pull/411#discussion_r1485645020


##########
pyiceberg/table/metadata.py:
##########
@@ -313,6 +315,34 @@ def construct_partition_specs(cls, data: Dict[str, Any]) 
-> Dict[str, Any]:
 
         return data
 
+    @model_validator(mode="before")
+    def construct_v1_spec_from_v2_fields(cls, data: Dict[str, Any]) -> 
Dict[str, Any]:
+        specs_field = "partition_specs"
+        default_spec_id_field = "default_spec_id"
+        if specs_field in data and default_spec_id_field in data:
+            found_spec = next((spec for spec in data[specs_field] if 
spec.spec_id == data[default_spec_id_field]), None)
+            if found_spec is not None:
+                spec_dict = found_spec.model_dump()
+                spec_dict['fields'] = list(spec_dict['fields'])

Review Comment:
   If I don't do this conversion from the tuple to a list what ends up 
happening is the read metadata from the JSON is a list but then the actual 
model in spec_dict['fields'] is a tuple. Since partition_spec is deprecated 
anyways and is a List[Dict[str, any]] I think we have the flexibility just to 
make the fields a list.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to