Fokko commented on code in PR #4358:
URL: https://github.com/apache/iceberg-python/pull/4358#discussion_r4700854009


##########
pyiceberg/table/inspect.py:
##########
@@ -39,7 +40,46 @@
 
 
 def _readable_bound(field_type: PrimitiveType, bound: bytes | None) -> Any | 
None:
-    return from_bytes(field_type, bound) if bound is not None else None
+    return _storage_value(from_bytes(field_type, bound)) if bound is not None 
else None
+
+
+def _storage_type(data_type: pa.DataType) -> pa.DataType:
+    """Return the storage type of a data type, replacing extension types 
inside structs, lists and maps."""
+    import pyarrow as pa
+
+    if isinstance(data_type, pa.BaseExtensionType):
+        return data_type.storage_type
+    if pa.types.is_struct(data_type):
+        return pa.struct([_storage_field(field) for field in data_type])
+    if pa.types.is_large_list(data_type):
+        return pa.large_list(_storage_field(data_type.value_field))
+    if pa.types.is_map(data_type):
+        return pa.map_(_storage_field(data_type.key_field), 
_storage_field(data_type.item_field))
+    return data_type
+
+

Review Comment:
   Nit: only `large_list` is unwrapped here. `schema_to_pyarrow` emits 
`large_list` for `ListType`, so this is fine for schemas built by PyIceberg, 
but a plain `list` or `fixed_size_list` with an extension element (hand-built 
arrow schema) would still hit the `ArrowNotImplementedError`. Is `large_list` 
guaranteed here, or should the other list kinds be unwrapped too?
   
   ```suggestion
       if isinstance(data_type, pa.BaseExtensionType):
           return data_type.storage_type
       if pa.types.is_struct(data_type):
           return pa.struct([_storage_field(field) for field in data_type])
       if pa.types.is_large_list(data_type) or pa.types.is_list(data_type) or 
pa.types.is_fixed_size_list(data_type):
           return pa.large_list(_storage_field(data_type.value_field))
       if pa.types.is_map(data_type):
           return pa.map_(_storage_field(data_type.key_field), 
_storage_field(data_type.item_field))
       return data_type
   ```



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