Skip to content

Add store.set_virtual_refs_arr()#1576

Closed
TomNicholas wants to merge 12 commits intomainfrom
arrow-virtual-refs
Closed

Add store.set_virtual_refs_arr()#1576
TomNicholas wants to merge 12 commits intomainfrom
arrow-virtual-refs

Conversation

@TomNicholas
Copy link
Copy Markdown
Member

@TomNicholas TomNicholas commented Jan 26, 2026

Attempt to close #1574. Doesn't seem to decrease memory usage, but allows zarr-developers/VirtualiZarr#861, which slashes write time by ~6x.

TomNicholas and others added 6 commits January 25, 2026 10:52
Add a new method that accepts Arrow arrays (StringArray, UInt64Array)
for setting virtual chunk references. This avoids creating millions of
Python objects when called from the Python bindings.

The method:
- Takes chunk_grid_shape to compute N-dimensional indices from flat arrays
- Validates array lengths match and product equals chunk count
- Iterates Arrow arrays efficiently and delegates to existing set_virtual_refs

This is gated behind the optional "arrow" feature which adds arrow-array
as a dependency.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tests the Arrow-based virtual refs method with a 2x2 chunk grid using
local filesystem virtual chunks. Verifies that chunks can be written
using Arrow arrays and read back correctly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds PyO3 bindings for the Arrow-based virtual refs method:
- Uses pyo3-arrow for zero-copy FFI from PyArrow arrays
- Accepts StringArray for locations, UInt64Array for offsets/lengths
- Calls core crate's set_virtual_refs_from_arrow method

Python API:
- IcechunkStore.set_virtual_refs_arr_async() accepts PyArrow arrays
- Significantly faster for large numbers of references

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Adds synchronous counterpart to set_virtual_refs_arr_async for cases
where async is not needed or desired.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add checksum parameter to apply a single checksum (datetime or ETag)
  to all chunks in the array
- Add arr_offset parameter to offset computed chunk indices, enabling
  append operations where new chunks start at non-zero indices
- Refactor flat_to_nd_indices to compute indices forward using strides
  rather than reverse iteration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
TomNicholas and others added 4 commits January 26, 2026 12:28
- Add set_chunk_refs bulk method to ChangeSet that does one hash lookup
  for all chunks instead of one per chunk
- Add set_node_chunk_refs bulk method to Session
- Change set_node_chunk_ref to take &NodeSnapshot instead of owned
- Update set_virtual_refs to use bulk method
- Make set_node_chunk_ref public for external use

This reduces the complexity from O(n) hash lookups to O(1) for setting
n chunk refs to the same array.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment thread icechunk/src/store.rs
.collect::<Result<Vec<_>, StoreError>>()?;

// Delegate to existing method
self.set_virtual_refs(array_path, validate_container, refs_iter).await
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we put all this validation in icechunk-python, we don't need to depend on arrow in the rust crate, do we? It would end up with just this call to .set_virtual_refs()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so... I don't actually need to pass arrow all the way down to the core IC rust crate, I just need to pass arrow to icechunk-python and have some way to pass refs in bulk from there to the core IC rust crate.

TomNicholas and others added 2 commits March 10, 2026 13:48
- icechunk/Cargo.toml: keep both arrow-array and backon deps, add arrow feature
- icechunk-python/Cargo.toml: use main's bumped versions with arrow feature
- icechunk/src/session.rs: use main's simpler set_chunk_ref (no splits), keep pub visibility
- icechunk/tests/test_virtual_refs.rs: keep both arrow and vcc relative URL tests
- Cargo.lock: regenerated

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- change_set.rs: remove ManifestSplits/ManifestExtents from set_chunk_refs (splits removed in main)
- session.rs: fix borrow issues in set_node_chunk_ref, remove get_splits from set_node_chunk_refs
- store.rs: use from_url instead of private from_absolute_path

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TomNicholas
Copy link
Copy Markdown
Member Author

We decided to try passing numpy array buffers instead of arrow arrays, that way we can avoid the dependency on arrow entirely.

@TomNicholas
Copy link
Copy Markdown
Member Author

Closed as this was implemented in #2049

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Method to allow setting array of virtual refs in a zero-copy way

2 participants