dragongu opened a new issue, #55752:
URL: https://github.com/apache/arrow/issues/55752

   ### Describe the enhancement requested
   
   `FileSystem.get_file_info(selector)` returns a list, so the whole listing is 
materialized before the caller sees the first entry. For a very large directory 
or prefix that means waiting for the complete listing, and holding all of it in 
memory, even when the caller only wants to process entries as they arrive, or 
to stop once it has found what it needs.
   
   It would be useful to overlap listing with processing: start working on the 
entries that have already been discovered while the rest are still being listed.
   
   The primary use case is listing very large S3 prefixes through PyArrow's 
native `S3FileSystem`. Callers should be able to start computing on objects 
from the first listing page while subsequent pages are still being fetched, 
rather than waiting for the entire prefix to be listed. The C++ S3 
implementation already pushes results as each `ListObjectsV2` page completes; 
exposing this to Python would enable pipelined listing and processing without 
changing the S3 backend.
   
   Arrow C++ already has `FileSystem::GetFileInfoGenerator()` for this, but it 
is not exposed in Python.
   
   Proposal, with naming open to discussion: add 
`FileSystem.get_file_info_iterator(selector)`, returning an iterator that 
yields `FileInfo` objects one at a time and fetches them from the filesystem in 
batches, so that a listing can be consumed incrementally and abandoned early.
   
   ```python
   for info in fs.get_file_info_iterator(FileSelector(path, recursive=True)):
       ...  # info is a FileInfo
   ```
   
   #### Backend differences
   
   How incremental this actually is depends on the backend. In C++ only 
`LocalFileSystem` and `S3FileSystem` override `GetFileInfoGenerator()`. 
`GcsFileSystem`, `AzureFileSystem`, `HadoopFileSystem` and `PyFileSystem`, 
which backs the fsspec integration, fall back to the base-class implementation, 
which lists everything and wraps the result in a single batch.
   
   On those backends the iterator yields the same entries as `get_file_info()`, 
but the full listing is still materialized on the first `next()` call, so 
neither the memory nor the early-termination benefit applies. Only 
`LocalFileSystem` and `S3FileSystem` would get those today.
   
   #### Possible follow-ups, out of scope here
   
   - A capability query so callers can tell whether a filesystem actually lists 
incrementally. There is currently no way to detect this: 
`GetFileInfoGenerator()` is a plain virtual method, and wrappers such as 
`SubTreeFileSystem` override it but forward to an inner filesystem, so the 
behaviour depends on what is wrapped.
   - Implementing `GetFileInfoGenerator()` for `GcsFileSystem` and 
`AzureFileSystem`, whose underlying APIs are already paginated but are 
currently collected into a single vector.
   
   
   ### Component(s)
   
   Python


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to