Fokko commented on code in PR #4118:
URL: https://github.com/apache/iceberg-python/pull/4118#discussion_r4306875236
##########
pyiceberg/io/pyarrow.py:
##########
@@ -2120,7 +2120,16 @@ def map(
)
if isinstance(value_result, pa.StructArray):
# Arrow does not allow reordering of fields, therefore we have
to copy the array :(
- return pa.MapArray.from_arrays(map_array.offsets, key_result,
value_result, arrow_field)
+ projected = pa.MapArray.from_arrays(map_array.offsets,
key_result, value_result, arrow_field)
+ # Keep the validity and offsets buffers of the original array,
otherwise null maps become empty maps
+ return pa.Array.from_buffers(
+ projected.type,
+ len(map_array),
+ map_array.buffers()[:2],
+ map_array.null_count,
+ map_array.offset,
+ [projected.values],
+ )
Review Comment:
How about using `StructArray`, and then we can pass iin the `arrow_field` as
the type:
```suggestion
entries = pa.StructArray.from_arrays(
[key_result, value_result],
fields=[arrow_field.key_field, arrow_field.item_field]
)
# Keep the validity and offsets buffers of the original
array, otherwise null maps become empty maps
return pa.Array.from_buffers(
arrow_field,
len(map_array),
map_array.buffers()[:2],
map_array.null_count,
map_array.offset,
[entries],
)
```
--
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]