Skip to content

Commit

Permalink
list methods on store
Browse files Browse the repository at this point in the history
  • Loading branch information
jhamman committed Apr 5, 2024
1 parent a7a2912 commit 213166f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/zarr/v3/store/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def get(
async def get_partial_values(
self, key_ranges: List[Tuple[str, Tuple[int, int]]]
) -> List[bytes]:
raise NotImplementedError
return [self.get(key, byte_range=byte_range) for key, byte_range in key_ranges]

async def exists(self, key: str) -> bool:
return key in self._store_dict
Expand All @@ -62,7 +62,7 @@ async def delete(self, key: str) -> None:
try:
del self._store_dict[key]
except KeyError:
pass # Q(JH): why not raise?
return None

async def set_partial_values(self, key_start_values: List[Tuple[str, int, bytes]]) -> None:
raise NotImplementedError
Expand Down
35 changes: 34 additions & 1 deletion src/zarr/v3/store/remote.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union, List

from zarr.v3.abc.store import Store
from zarr.v3.store.core import _dereference_path
Expand All @@ -12,6 +12,10 @@
from fsspec.asyn import AsyncFileSystem


# TODOs:
# * cache fsspec objects after instantiation


class RemoteStore(Store):
supports_writes: bool = True
supports_partial_writes: bool = False
Expand Down Expand Up @@ -93,3 +97,32 @@ async def exists(self, key: str) -> bool:
fs, root = self._make_fs()
path = _dereference_path(root, key)
return await fs._exists(path)

async def list(self) -> List[str]:
fs, root = self._make_fs()
keys = await fs._glob(root + "/*")
print(keys)
return [k.replace(root + "/", "") for k in keys]

async def list_prefix(self, prefix: str) -> List[str]:
return [key for key in self._store_dict if key.startswith(prefix)]

async def list_dir(self, prefix: str) -> List[str]:
if prefix == "":
return list({key.split("/", maxsplit=1)[0] for key in self._store_dict})
else:
return list(
{
key.strip(prefix + "/").split("/")[0]
for key in self._store_dict
if (key.startswith(prefix + "/") and key != prefix)
}
)

async def set_partial_values(self, key_start_values: List[Tuple[str, int, bytes]]) -> None:
raise NotImplementedError

async def get_partial_values(
self, key_ranges: List[Tuple[str, Tuple[int, int]]]
) -> List[bytes]:
return [await self.get(key, byte_range=byte_range) for key, byte_range in key_ranges]

0 comments on commit 213166f

Please sign in to comment.