amogh-jahagirdar commented on code in PR #411: URL: https://github.com/apache/iceberg-python/pull/411#discussion_r1485627063
########## 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: + specs = data[specs_field] + spec_id = data[default_spec_id_field] + for spec in specs: + if spec.spec_id == spec_id: + data["partition_spec"] = [spec.model_dump()] + return data + + return data + + @model_validator(mode="before") + def construct_v1_schema_from_v2_fields(cls, data: Dict[str, Any]) -> Dict[str, Any]: + schemas_field = "schemas" + current_schema_id_field = "current_schema_id" + if schemas_field in data and current_schema_id_field in data: + schemas = data[schemas_field] + current_schema_id = data[current_schema_id_field] + for schema in schemas: + if schema.schema_id == current_schema_id: + data["schema"] = schema Review Comment: There's probably a more pythonic way to do this -- 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