Skip to content
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

ReferenceFileSystem: streaming support for _open #1771

Closed
skshetry opened this issue Jan 13, 2025 · 1 comment · Fixed by #1778
Closed

ReferenceFileSystem: streaming support for _open #1771

skshetry opened this issue Jan 13, 2025 · 1 comment · Fixed by #1778

Comments

@skshetry
Copy link
Contributor

skshetry commented Jan 13, 2025

Hi, I am using ReferenceFileSystem as a sort of virtual filesystem, similar to how you have described it in stackoverflow - Does fsspec support virtual filesystems such as pyfileysystem.

It works great for my use-case, but I have encountered an issue - the _open API reads the entire file instead of streaming it.

def _open(self, path, mode="rb", block_size=None, cache_options=None, **kwargs):
data = self.cat_file(path) # load whole chunk into memory
return io.BytesIO(data)

This behaviour is expected and is documented as such:

This FileSystem is read-only. It is designed to be used with async
targets (for now). This FileSystem only allows whole-file access, no
``open``. We do not get original file details from the target FS.

I’m curious if there’s a specific reason _open was implemented to load the entire file instead of allowing for streaming access. Could it be that I’m misusing ReferenceFileSystem? If not, I’d be happy to work on a PR to implement streaming support. Let me know if this would be useful!

EDIT: I'm basically using it as follows, for pyarrow to preserve partitioning format that it infers from filepath.

path = "s3://bucket/parquets/first_name=Alice/5c6de-0.parquet"
fs = ReferenceFileSystem(fo={path: ["/path/to/a/local/cache"]}
ds = dataset(path, filesystem=fs, **kwargs)
@martindurant
Copy link
Member

An more complete implementation for a file-like object based on ReferenceFS is totally possible and would be welcome. The main use case of the filesystem today is with zarr, which always loads a whole reference at a time, so it was not needed.

I believe all the pieces are there for a relatively simple implementation: AbstractFileSystem merely needs to know how to fetch some given byterange for a particular path, which would typeically be (offset + loc)-(offset + loc + size), where offset if the chunks position according to the references, loc the current file-like's position and size the number of bytes requested.

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 a pull request may close this issue.

2 participants