-
Notifications
You must be signed in to change notification settings - Fork 5
feat: obstore support
#138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use pyo3::PyErr; | ||
| use zarrs::storage::{ | ||
| ReadableWritableListableStorage, storage_adapter::async_to_sync::AsyncToSyncStorageAdapter, | ||
| }; | ||
| use zarrs_object_store::{AsyncObjectStore, object_store::ObjectStore}; | ||
|
|
||
| use crate::runtime::tokio_block_on; | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct ObStoreConfig { | ||
| store: Arc<dyn ObjectStore>, | ||
| } | ||
|
|
||
| impl ObStoreConfig { | ||
| pub fn new(store: Arc<dyn ObjectStore>) -> Self { | ||
| Self { store } | ||
| } | ||
| } | ||
|
|
||
| impl TryInto<ReadableWritableListableStorage> for &ObStoreConfig { | ||
| type Error = PyErr; | ||
|
|
||
| fn try_into(self) -> Result<ReadableWritableListableStorage, Self::Error> { | ||
| let async_store = Arc::new(AsyncObjectStore::new(self.store.clone())); | ||
| let sync_store = Arc::new(AsyncToSyncStorageAdapter::new( | ||
| async_store, | ||
| tokio_block_on(), | ||
| )); | ||
| Ok(sync_store) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import tempfile | ||
| import warnings | ||
|
|
||
| import numpy as np | ||
| import zarr | ||
| from obstore.store import HTTPStore, LocalStore | ||
| from zarr.storage import ObjectStore | ||
|
|
||
| from .test_zarrs_http import ARR_REF, URL | ||
|
|
||
| # Suppress the expected warning about cross-library object store usage | ||
| warnings.filterwarnings( | ||
| "ignore", | ||
| message="Successfully reconstructed a store defined in another Python module", | ||
| ) | ||
|
|
||
|
|
||
| def test_obstore_local_store(): | ||
| """Test zarrs-python with obstore LocalStore""" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| # Create obstore LocalStore and wrap with zarr's ObjectStore | ||
| obstore_local = LocalStore(prefix=tmpdir) | ||
| store = ObjectStore(obstore_local, read_only=False) | ||
|
|
||
| # Create zarr array with obstore | ||
| # Expect a warning about cross-library object store usage | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore", RuntimeWarning) | ||
| arr = zarr.open_array( | ||
| store=store, | ||
| mode="w", | ||
| shape=(100, 100), | ||
| chunks=(10, 10), | ||
| dtype="f4", | ||
| ) | ||
|
|
||
| # Write data | ||
| data = np.random.rand(100, 100).astype("f4") | ||
| arr[:] = data | ||
|
|
||
| # Read back and verify | ||
| arr2 = zarr.open_array(store=store, mode="r") | ||
| assert arr2.shape == (100, 100) | ||
| assert np.allclose(arr2[:], data) | ||
|
|
||
|
|
||
| def test_obstore_http(): | ||
| """Test zarrs-python with obstore HTTPStore - similar to test_zarrs_http""" | ||
| # Create HTTPStore from the test URL | ||
| http_store = HTTPStore.from_url(URL) | ||
| store = ObjectStore(http_store, read_only=True) | ||
|
|
||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore", RuntimeWarning) | ||
| arr = zarr.open_array(store=store, mode="r") | ||
|
|
||
| # Verify shape and data match the reference | ||
| assert arr.shape == (8, 8) | ||
| assert np.allclose(arr[:], ARR_REF, equal_nan=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear here, what this is doing is taking the configuration from an existing obstore store and recreating a new store with the same parameters in the currently-linked
object_storecrate. So that means any connection pooling will not be shared between the user's inputobstoreinstance and the instance you use to make your own fetches.That's why the original idea in
pyo3-object_storewas that downstream crates would re-export the obstore store creation API, so that there wouldn't be any of this "dynamic linking" across crates. Since we don't have real dynamic linking, in effect we have to re-create all the necessary resources in the target pyo3 module.