rahulsmahadev commented on code in PR #4544:
URL: https://github.com/apache/iceberg-python/pull/4544#discussion_r4790992346


##########
pyiceberg/table/__init__.py:
##########
@@ -2457,7 +2465,25 @@ def from_rest_response(
         )
 
 
-def _rest_file_to_data_file(rest_file: RESTContentFile, 
default_referenced_data_file: str | None = None) -> DataFile:
+def _serialize_bounds(raw_bounds: dict[int, Any] | None, schema: Schema | 
None) -> dict[int, bytes] | None:
+    if not raw_bounds:
+        return None
+    serialized: dict[int, bytes] = {}
+    for field_id, val in raw_bounds.items():
+        if isinstance(val, bytes):
+            serialized[field_id] = val
+        elif schema is not None:
+            field = schema.find_field(field_id)
+            if field is not None and isinstance(field.field_type, 
PrimitiveType):
+                serialized[field_id] = to_bytes(field.field_type, val)

Review Comment:
   One detail for the hex version: `RestCatalog` parses responses with 
`validate_json`, where pydantic turns a 32-digit hex value into a `UUID`, so 
16-byte bounds need a `str`-valued map. With `KeyValueMap[str]` for 
`lower_bounds`/`upper_bounds` and `{field_id: bytes.fromhex(value) for ...}`, a 
scratch copy got the bytes pyiceberg writes in manifests for all 14 primitive 
types, including uuid, decimal and fixed[16].



##########
pyiceberg/table/__init__.py:
##########
@@ -2466,11 +2492,17 @@ def _rest_file_to_data_file(rest_file: RESTContentFile, 
default_referenced_data_
         value_counts = rest_file.value_counts.to_dict() if 
rest_file.value_counts else None
         null_value_counts = rest_file.null_value_counts.to_dict() if 
rest_file.null_value_counts else None
         nan_value_counts = rest_file.nan_value_counts.to_dict() if 
rest_file.nan_value_counts else None
+        lower_bounds = _serialize_bounds(rest_file.lower_bounds.to_dict() if 
rest_file.lower_bounds else None, table_schema)
+        upper_bounds = _serialize_bounds(rest_file.upper_bounds.to_dict() if 
rest_file.upper_bounds else None, table_schema)
     else:
         column_sizes = None
         value_counts = None
         null_value_counts = None
         nan_value_counts = None
+        lower_bounds = None
+        upper_bounds = None
+
+    key_metadata = base64.b64decode(rest_file.key_metadata, validate=True) if 
rest_file.key_metadata else None

Review Comment:
   The REST spec types `key-metadata` as a `BinaryTypeValue` (uppercase hex); 
the base64 in `table/metadata.py` is for the table metadata's 
`encrypted-key-metadata`. Something like (and drop the `base64` import):
   
   ```suggestion
       key_metadata = bytes.fromhex(rest_file.key_metadata) if 
rest_file.key_metadata else None
   ```



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