zarrs_icechunk 0.5.1

icechunk store support for the zarrs crate
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
//! [`icechunk`] store support for the [`zarrs`](https://docs.rs/zarrs/latest/zarrs/index.html) crate.
//!
//! Icechunk is a transactional store that enables `git`-like version control of Zarr hierarchies.
//!
//! `zarrs_icechunk` can read data in a range of archival formats (e.g., [`netCDF4`](https://www.unidata.ucar.edu/software/netcdf/), [`HDF5`](https://www.hdfgroup.org/solutions/hdf5/), etc.) that are converted to `icechunk`-backed "virtual Zarr datacubes" via [`VirtualiZarr`](https://github.com/zarr-developers/VirtualiZarr) (example below).
//!
//! ## Version Compatibility Matrix
//!
#![doc = include_str!("../doc/version_compatibility_matrix.md")]
//!
//! ## Examples
//! ### Basic Usage and Version Control
//! ```
//! # use std::sync::Arc;
//! # use zarrs_storage::{AsyncWritableStorageTraits, StoreKey};
//! # use tokio::sync::RwLock;
//! # use std::collections::HashMap;
//! use icechunk::{Repository, RepositoryConfig, repository::VersionInfo};
//! use zarrs_icechunk::AsyncIcechunkStore;
//! # tokio_test::block_on(async {
//! // Create an icechunk repository
//! let storage = icechunk::new_in_memory_storage().await?;
//! let config = RepositoryConfig::default();
//! let repo = Repository::create(Some(config), storage, Default::default(), Default::default(), true).await?;
//!
//! // Do some array/metadata manipulation with zarrs, then commit a snapshot
//! let session = repo.writable_session("main").await?;
//! let store = Arc::new(AsyncIcechunkStore::new(session));
//! # let root_json = StoreKey::new("zarr.json").unwrap();
//! # store.set(&root_json, r#"{"zarr_format":3,"node_type":"group"}"#.into()).await?;
//! let snapshot0 = store.session().write().await.commit("Initial commit").execute().await?;
//!
//! // Do some more array/metadata manipulation, then commit another snapshot
//! let session = repo.writable_session("main").await?;
//! let store = Arc::new(AsyncIcechunkStore::new(session));
//! # store.set(&root_json, r#"{"zarr_format":3,"node_type":"group","attributes":{"a":"b"}}"#.into()).await?;
//! let snapshot1 = store.session().write().await.commit("Update data").execute().await?;
//!
//! // Checkout the first snapshot
//! let session = repo.readonly_session(&VersionInfo::SnapshotId(snapshot0)).await?;
//! let store = Arc::new(AsyncIcechunkStore::new(session));
//! # Ok::<_, Box<dyn std::error::Error>>(())
//! # }).unwrap();
//! ```
//!
//! ### Virtualise NetCDF as Zarr (via [`VirtualiZarr`](https://github.com/zarr-developers/VirtualiZarr))
//! Decode a virtual Zarr array [`/examples/data/test.icechunk.zarr`]:
//! ```bash
//! cargo run --example virtualizarr_netcdf
//! ```
//! This references `/examples/data/test[0,1].nc` hosted in this repository over HTTP.
//! [`/examples/data/test.icechunk.zarr`] was created with [`/examples/virtualizarr_netcdf.py`](https://github.com/zarrs/zarrs_icechunk/blob/main/examples/virtualizarr_netcdf.py).
//!
//! ## Licence
//! `zarrs_icechunk` is licensed under either of
//! - the Apache License, Version 2.0 [LICENSE-APACHE](https://docs.rs/crate/zarrs_icechunk/latest/source/LICENCE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0> or
//! - the MIT license [LICENSE-MIT](https://docs.rs/crate/zarrs_icechunk/latest/source/LICENCE-MIT) or <http://opensource.org/licenses/MIT>, at your option.
//!
//! [`/examples/data/test.icechunk.zarr`]: https://github.com/zarrs/zarrs_icechunk/tree/main/examples/data/test.icechunk.zarr

use std::sync::Arc;

use futures::{future, stream::FuturesUnordered, StreamExt, TryStreamExt};
pub use icechunk;

use tokio::sync::RwLock;
use zarrs_storage::{
    byte_range::{ByteRange, ByteRangeIterator},
    AsyncListableStorageTraits, AsyncMaybeBytesIterator, AsyncReadableStorageTraits,
    AsyncWritableStorageTraits, Bytes, MaybeBytes, OffsetBytesIterator, StorageError, StoreKey,
    StoreKeys, StoreKeysPrefixes, StorePrefix,
};

fn handle_err(err: icechunk::store::StoreError) -> StorageError {
    StorageError::Other(err.to_string())
}

/// Map [`icechunk::zarr::StoreError::NotFound`] to None, pass through other errors
fn handle_result_notfound<T>(
    result: Result<T, icechunk::store::StoreError>,
) -> Result<Option<T>, StorageError> {
    match result {
        Ok(result) => Ok(Some(result)),
        Err(err) => {
            if matches!(
                err.kind(),
                &icechunk::store::StoreErrorKind::NotFound { .. }
            ) {
                Ok(None)
            } else {
                Err(StorageError::Other(err.to_string()))
            }
        }
    }
}

fn handle_result<T>(result: Result<T, icechunk::store::StoreError>) -> Result<T, StorageError> {
    result.map_err(handle_err)
}

/// An asynchronous store backed by an [`icechunk::session::Session`].
pub struct AsyncIcechunkStore {
    icechunk_session: Arc<RwLock<icechunk::session::Session>>,
}

impl From<Arc<RwLock<icechunk::session::Session>>> for AsyncIcechunkStore {
    fn from(icechunk_session: Arc<RwLock<icechunk::session::Session>>) -> Self {
        Self { icechunk_session }
    }
}

impl AsyncIcechunkStore {
    async fn store(&self) -> icechunk::Store {
        icechunk::Store::from_session(self.icechunk_session.clone()).await
    }

    /// Create a new [`AsyncIcechunkStore`].
    #[must_use]
    pub fn new(icechunk_session: icechunk::session::Session) -> Self {
        Self {
            icechunk_session: Arc::new(RwLock::new(icechunk_session)),
        }
    }

    /// Return the inner [`icechunk::session::Session`].
    #[must_use]
    pub fn session(&self) -> Arc<RwLock<icechunk::session::Session>> {
        self.icechunk_session.clone()
    }

    // TODO: Wait for async closures
    // // /// Run a method on the underlying session.
    // pub async fn with_session<F, T>(&self, f: F) -> icechunk::session::SessionResult<T>
    // where
    //     F: async FnOnce(&icechunk::session::Session) -> icechunk::session::SessionResult<T>,
    // {
    //     let session = self.icechunk_session.read().await;
    //     f(&session).await
    // }

    // /// Run a mutable method on the underlying session.
    // pub async fn with_session_mut<F, T>(&self, f: F) -> icechunk::session::SessionResult<T>
    // where
    //     F: async FnOnce(&icechunk::session::Session) -> icechunk::session::SessionResult<T>,
    // {
    //     let mut session = self.icechunk_session.write().await;
    //     f(&mut session).await
    // }
}

#[async_trait::async_trait]
impl AsyncReadableStorageTraits for AsyncIcechunkStore {
    async fn get(&self, key: &StoreKey) -> Result<MaybeBytes, StorageError> {
        handle_result_notfound(
            self.store()
                .await
                .get(key.as_str(), &icechunk::format::ByteRange::ALL)
                .await,
        )
    }

    async fn get_partial_many<'a>(
        &'a self,
        key: &StoreKey,
        byte_ranges: ByteRangeIterator<'a>,
    ) -> Result<AsyncMaybeBytesIterator<'a>, StorageError> {
        let byte_ranges: Vec<_> = byte_ranges
            .map(|byte_range| {
                let key = key.to_string();
                let byte_range = match byte_range {
                    ByteRange::FromStart(offset, None) => {
                        icechunk::format::ByteRange::from_offset(offset)
                    }
                    ByteRange::FromStart(offset, Some(length)) => {
                        icechunk::format::ByteRange::from_offset_with_length(offset, length)
                    }
                    ByteRange::Suffix(length) => icechunk::format::ByteRange::Last(length),
                };
                (key, byte_range)
            })
            .collect();
        let result =
            handle_result_notfound(self.store().await.get_partial_values(byte_ranges).await)?;
        if let Some(result) = result {
            Ok(Some(
                futures::stream::iter(result.into_iter().map(handle_result)).boxed(),
            ))
        } else {
            Ok(None)
        }
    }

    // NOTE: this does not differentiate between not found and empty
    async fn size_key(&self, key: &StoreKey) -> Result<Option<u64>, StorageError> {
        let key = key.to_string();
        handle_result(self.store().await.getsize(&key).await).map(Some)
    }

    fn supports_get_partial(&self) -> bool {
        true
    }
}

#[async_trait::async_trait]
impl AsyncWritableStorageTraits for AsyncIcechunkStore {
    async fn set(&self, key: &StoreKey, value: Bytes) -> Result<(), StorageError> {
        handle_result(self.store().await.set(key.as_str(), value).await)?;
        Ok(())
    }

    async fn set_partial_many<'a>(
        &'a self,
        _key: &StoreKey,
        _offset_values: OffsetBytesIterator<'a>,
    ) -> Result<(), StorageError> {
        if self
            .store()
            .await
            .supports_partial_writes()
            .map_err(handle_err)?
        {
            // FIXME: Upstream: icechunk::Store does not support partial writes
            Err(StorageError::Unsupported(
                "the store does not support partial writes".to_string(),
            ))
        } else {
            Err(StorageError::Unsupported(
                "the store does not support partial writes".to_string(),
            ))
        }
    }

    async fn erase(&self, key: &StoreKey) -> Result<(), StorageError> {
        if self.store().await.supports_deletes().map_err(handle_err)? {
            handle_result_notfound(self.store().await.delete(key.as_str()).await)?;
            Ok(())
        } else {
            Err(StorageError::Unsupported(
                "the store does not support deletion".to_string(),
            ))
        }
    }

    async fn erase_prefix(&self, prefix: &StorePrefix) -> Result<(), StorageError> {
        if self.store().await.supports_deletes().map_err(handle_err)? {
            let keys = self
                .store()
                .await
                .list_prefix(prefix.as_str())
                .await
                .map_err(handle_err)?
                .try_collect::<Vec<_>>() // TODO: do not collect, use try_for_each
                .await
                .map_err(handle_err)?;
            for key in keys {
                self.store().await.delete(&key).await.map_err(handle_err)?;
            }
            Ok(())
        } else {
            Err(StorageError::Unsupported(
                "the store does not support deletion".to_string(),
            ))
        }
    }

    fn supports_set_partial(&self) -> bool {
        false
    }
}

#[async_trait::async_trait]
impl AsyncListableStorageTraits for AsyncIcechunkStore {
    async fn list(&self) -> Result<StoreKeys, StorageError> {
        let keys = self.store().await.list().await.map_err(handle_err)?;
        keys.map(|key| match key {
            Ok(key) => Ok(StoreKey::new(&key)?),
            Err(err) => Err(StorageError::Other(err.to_string())),
        })
        .try_collect::<Vec<_>>()
        .await
    }

    async fn list_prefix(&self, prefix: &StorePrefix) -> Result<StoreKeys, StorageError> {
        let keys = self
            .store()
            .await
            .list_prefix(prefix.as_str())
            .await
            .map_err(handle_err)?;
        keys.map(|key| match key {
            Ok(key) => Ok(StoreKey::new(&key)?),
            Err(err) => Err(StorageError::Other(err.to_string())),
        })
        .try_collect::<Vec<_>>()
        .await
    }

    async fn list_dir(&self, prefix: &StorePrefix) -> Result<StoreKeysPrefixes, StorageError> {
        let keys_prefixes = self
            .store()
            .await
            .list_dir_items(prefix.as_str())
            .await
            .map_err(handle_err)?;
        let mut keys = vec![];
        let mut prefixes = vec![];
        keys_prefixes
            .map_err(handle_err)
            .map(|item| {
                match item? {
                    icechunk::store::ListDirItem::Key(key) => {
                        keys.push(StoreKey::new(format!("{}{}", prefix.as_str(), &key))?);
                    }
                    icechunk::store::ListDirItem::Prefix(prefix_inner) => {
                        prefixes.push(StorePrefix::new(format!(
                            "{}{}/",
                            prefix.as_str(),
                            &prefix_inner
                        ))?);
                    }
                }
                Ok::<_, StorageError>(())
            })
            .try_for_each(|_| future::ready(Ok(())))
            .await?;

        Ok(StoreKeysPrefixes::new(keys, prefixes))
    }

    async fn size_prefix(&self, prefix: &StorePrefix) -> Result<u64, StorageError> {
        let keys = self.list_prefix(prefix).await?;
        let mut futures: FuturesUnordered<_> = keys
            .into_iter()
            .map(|key| async move {
                let key = key.to_string();
                handle_result(self.store().await.getsize(&key).await)
            })
            .collect();
        let mut sum = 0;
        while let Some(result) = futures.next().await {
            sum += result?;
        }
        Ok(sum)
    }

    async fn size(&self) -> Result<u64, StorageError> {
        self.size_prefix(&StorePrefix::root()).await
    }
}

#[cfg(test)]
mod tests {
    use icechunk::{repository::VersionInfo, Repository, RepositoryConfig};

    use super::*;
    use std::error::Error;

    fn remove_whitespace(s: &str) -> String {
        s.chars().filter(|c| !c.is_whitespace()).collect()
    }

    // NOTE: The icechunk store is not a run-of-the-mill Zarr store that knows nothing about Zarr.
    // It adds additional requirements on keys/data (like looking for known zarr metadata, c prefix, etc.)
    // Thus it does not support the current zarrs async store test suite.
    // The test suite could be changed to only create a structure that is actually zarr specific (standard keys, actually valid group/array json, c/ prefix etc)
    #[tokio::test]
    #[ignore]
    async fn icechunk() -> Result<(), Box<dyn Error>> {
        let storage = icechunk::new_in_memory_storage().await?;
        let config = RepositoryConfig::default();
        let repo = Repository::create(
            Some(config),
            storage,
            Default::default(),
            Default::default(),
            true,
        )
        .await?;
        let store = AsyncIcechunkStore::new(repo.writable_session("main").await?);

        zarrs_storage::store_test::async_store_write(&store).await?;
        zarrs_storage::store_test::async_store_read(&store).await?;
        zarrs_storage::store_test::async_store_list(&store).await?;

        Ok(())
    }

    #[tokio::test]
    async fn icechunk_time_travel() -> Result<(), Box<dyn Error>> {
        let storage = icechunk::new_in_memory_storage().await?;
        let config = RepositoryConfig::default();
        let repo = Repository::create(
            Some(config),
            storage,
            Default::default(),
            Default::default(),
            true,
        )
        .await?;

        let json = r#"{
            "zarr_format": 3,
            "node_type": "group"
        }"#;
        let json: String = remove_whitespace(json);

        let json_updated = r#"{
            "zarr_format": 3,
            "node_type": "group",
            "attributes": {
                "icechunk": "x zarrs"
            }
        }"#;
        let json_updated: String = remove_whitespace(json_updated);

        let root_json = StoreKey::new("zarr.json").unwrap();

        let store = AsyncIcechunkStore::new(repo.writable_session("main").await?);
        assert_eq!(store.get(&root_json).await?, None);
        store.set(&root_json, json.clone().into()).await?;
        assert_eq!(store.get(&root_json).await?, Some(json.clone().into()));
        let snapshot0 = store
            .session()
            .write()
            .await
            .commit("intial commit")
            .execute()
            .await?;

        let store = AsyncIcechunkStore::new(repo.writable_session("main").await?);
        store.set(&root_json, json_updated.clone().into()).await?;
        let _snapshot1 = store
            .session()
            .write()
            .await
            .commit("write attributes")
            .execute()
            .await?;
        assert_eq!(store.get(&root_json).await?, Some(json_updated.into()));

        let session = repo
            .readonly_session(&VersionInfo::SnapshotId(snapshot0))
            .await?;
        let store = AsyncIcechunkStore::new(session);
        assert_eq!(store.get(&root_json).await?, Some(json.clone().into()));

        Ok(())
    }

    #[tokio::test]
    async fn list_dir_and_list_prefix_nested() -> Result<(), Box<dyn Error>> {
        // Create an icechunk repository with a deeply nested zarr hierarchy
        let storage = icechunk::new_in_memory_storage().await?;
        let config = RepositoryConfig::default();
        let repo = Repository::create(
            Some(config),
            storage,
            Default::default(),
            Default::default(),
            true,
        )
        .await?;
        let store = AsyncIcechunkStore::new(repo.writable_session("main").await?);

        let group_json = r#"{"zarr_format":3,"node_type":"group"}"#;
        let array_json = r#"{"zarr_format":3,"node_type":"array","shape":[10, 10],"data_type":"int32","chunk_grid":{"name":"regular","configuration":{"chunk_shape":[5, 5]}},"chunk_key_encoding":{"name":"default","configuration":{"separator":"/"}},"fill_value":0,"codecs":[{"name":"bytes","configuration":{"endian":"little"}}]}"#;

        // Create a deeply nested hierarchy:
        // root/
        //   zarr.json
        //   group0/
        //     zarr.json
        //     group1/
        //       zarr.json
        //       array0/
        //         zarr.json
        //         c/0/0
        //         c/0/1
        //       array1/
        //         zarr.json
        //         c/0/0

        // Create groups
        store
            .set(&StoreKey::new("zarr.json")?, group_json.into())
            .await?;
        store
            .set(&StoreKey::new("group0/zarr.json")?, group_json.into())
            .await?;
        store
            .set(
                &StoreKey::new("group0/group1/zarr.json")?,
                group_json.into(),
            )
            .await?;

        // Create arrays
        store
            .set(
                &StoreKey::new("group0/group1/array0/zarr.json")?,
                array_json.into(),
            )
            .await?;
        store
            .set(
                &StoreKey::new("group0/group1/array0/c/0/0")?,
                vec![0u8; 20].into(),
            )
            .await?;
        store
            .set(
                &StoreKey::new("group0/group1/array0/c/0/1")?,
                vec![1u8; 20].into(),
            )
            .await?;

        store
            .set(
                &StoreKey::new("group0/group1/array1/zarr.json")?,
                array_json.into(),
            )
            .await?;
        store
            .set(
                &StoreKey::new("group0/group1/array1/c/0/0")?,
                vec![2u8; 20].into(),
            )
            .await?;

        // Commit the data
        store
            .session()
            .write()
            .await
            .commit("Create nested hierarchy")
            .execute()
            .await?;

        // Test list_dir at root
        let root_items = store.list_dir(&StorePrefix::root()).await?;
        assert_eq!(root_items.keys().len(), 1); // zarr.json
        assert_eq!(root_items.prefixes().len(), 1); // group0/
        assert!(root_items.keys().contains(&StoreKey::new("zarr.json")?));
        assert!(root_items
            .prefixes()
            .contains(&StorePrefix::new("group0/")?));

        // Test list_dir at group0
        let group0_items = store.list_dir(&StorePrefix::new("group0/")?).await?;
        assert_eq!(group0_items.keys().len(), 1); // zarr.json
        assert_eq!(group0_items.prefixes().len(), 1); // group1/
        assert!(group0_items
            .keys()
            .contains(&StoreKey::new("group0/zarr.json")?));
        assert!(group0_items
            .prefixes()
            .contains(&StorePrefix::new("group0/group1/")?));

        // Test list_dir at group1
        let group1_items = store.list_dir(&StorePrefix::new("group0/group1/")?).await?;
        assert_eq!(group1_items.keys().len(), 1); // zarr.json
        assert_eq!(group1_items.prefixes().len(), 2); // array0/, array1/
        assert!(group1_items
            .keys()
            .contains(&StoreKey::new("group0/group1/zarr.json")?));
        assert!(group1_items
            .prefixes()
            .contains(&StorePrefix::new("group0/group1/array0/")?));
        assert!(group1_items
            .prefixes()
            .contains(&StorePrefix::new("group0/group1/array1/")?));

        // Test list_dir inside array0
        let array0_items = store
            .list_dir(&StorePrefix::new("group0/group1/array0/")?)
            .await?;
        assert_eq!(array0_items.keys().len(), 1); // zarr.json
        assert_eq!(array0_items.prefixes().len(), 1); // c/
        assert!(array0_items
            .keys()
            .contains(&StoreKey::new("group0/group1/array0/zarr.json")?));
        assert!(array0_items
            .prefixes()
            .contains(&StorePrefix::new("group0/group1/array0/c/")?));

        // Test list_dir inside array0/c/ directory
        let array0_c_items = store
            .list_dir(&StorePrefix::new("group0/group1/array0/c/")?)
            .await?;
        assert_eq!(array0_c_items.keys().len(), 0); // no direct keys
        assert_eq!(array0_c_items.prefixes().len(), 1); // 0/
        assert!(array0_c_items
            .prefixes()
            .contains(&StorePrefix::new("group0/group1/array0/c/0/")?));

        // Test list_dir inside array0/c/0/ directory
        let array0_c0_items = store
            .list_dir(&StorePrefix::new("group0/group1/array0/c/0/")?)
            .await?;
        assert_eq!(array0_c0_items.keys().len(), 2); // 0, 1
        assert_eq!(array0_c0_items.prefixes().len(), 0); // no subdirectories
        assert!(array0_c0_items
            .keys()
            .contains(&StoreKey::new("group0/group1/array0/c/0/0")?));
        assert!(array0_c0_items
            .keys()
            .contains(&StoreKey::new("group0/group1/array0/c/0/1")?));

        // Test list_prefix at root (should get all keys recursively)
        let all_keys = store.list_prefix(&StorePrefix::root()).await?;
        assert_eq!(all_keys.len(), 8); // Total of 8 keys in the hierarchy

        // Test list_prefix at group0
        let group0_keys = store.list_prefix(&StorePrefix::new("group0/")?).await?;
        assert_eq!(group0_keys.len(), 7); // All keys under group0/

        // Test list_prefix at group1
        let group1_keys = store
            .list_prefix(&StorePrefix::new("group0/group1/")?)
            .await?;
        assert_eq!(group1_keys.len(), 6); // zarr.json + 2 arrays with their chunks

        // Test list_prefix for array0 (should get all chunks recursively)
        let array0_keys = store
            .list_prefix(&StorePrefix::new("group0/group1/array0/")?)
            .await?;
        assert_eq!(array0_keys.len(), 3); // zarr.json + 2 chunks
        assert!(array0_keys.contains(&StoreKey::new("group0/group1/array0/zarr.json")?));
        assert!(array0_keys.contains(&StoreKey::new("group0/group1/array0/c/0/0")?));
        assert!(array0_keys.contains(&StoreKey::new("group0/group1/array0/c/0/1")?));

        // Test list_prefix for array1 (should get all chunks recursively)
        let array1_keys = store
            .list_prefix(&StorePrefix::new("group0/group1/array1/")?)
            .await?;
        assert_eq!(array1_keys.len(), 2); // zarr.json + 1 chunk
        assert!(array1_keys.contains(&StoreKey::new("group0/group1/array1/zarr.json")?));
        assert!(array1_keys.contains(&StoreKey::new("group0/group1/array1/c/0/0")?));

        Ok(())
    }
}