Skip to content

Parquet filepath parsing error #8028

Closed

Description

@jrbourbeau

I attempted to load a large Parquet dataset on S3 with

import dask.dataframe as dd

df = dd.read_parquet("s3://oss-shared-scratch/timeseries.parquet", storage_options=storage_options)

but encountered the following error from pyarrow (full traceback down below):

OSError: Passed non-file path: oss-shared-scratch/timeseries.parquet

I'm not sure if the underlying issue is with pyarrow or dask or fsspec. I'll attempt to create a minimal reproducer, but thought the traceback might be useful by itself.

cc @jorisvandenbossche @rjzamora

Full traceback:
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<timed exec> in <module>

~/projects/dask/dask/dask/dataframe/io/parquet/core.py in read_parquet(path, columns, filters, categories, index, storage_options, engine, gather_statistics, split_row_groups, read_from_paths, chunksize, aggregate_files, **kwargs)
    314         gather_statistics = True
    315 
--> 316     read_metadata_result = engine.read_metadata(
    317         fs,
    318         paths,

~/projects/dask/dask/dask/dataframe/io/parquet/arrow.py in read_metadata(cls, fs, paths, categories, index, gather_statistics, filters, split_row_groups, read_from_paths, chunksize, aggregate_files, **kwargs)
    540             split_row_groups,
    541             gather_statistics,
--> 542         ) = cls._gather_metadata(
    543             paths,
    544             fs,

~/projects/dask/dask/dask/dataframe/io/parquet/arrow.py in _gather_metadata(cls, paths, fs, split_row_groups, gather_statistics, filters, index, dataset_kwargs)
   1786 
   1787         # Step 1: Create a ParquetDataset object
-> 1788         dataset, base, fns = _get_dataset_object(paths, fs, filters, dataset_kwargs)
   1789         if fns == [None]:
   1790             # This is a single file. No danger in gathering statistics

~/projects/dask/dask/dask/dataframe/io/parquet/arrow.py in _get_dataset_object(paths, fs, filters, dataset_kwargs)
   1754         base = paths[0]
   1755         fns = [None]
-> 1756         dataset = pq.ParquetDataset(paths[0], filesystem=fs, **kwargs)
   1757 
   1758     return dataset, base, fns

~/mambaforge/envs/coiled/lib/python3.9/site-packages/pyarrow/parquet.py in __init__(self, path_or_paths, filesystem, schema, metadata, split_row_groups, validate_schema, filters, metadata_nthreads, read_dictionary, memory_map, buffer_size, partitioning, use_legacy_dataset, pre_buffer, coerce_int96_timestamp_unit)
   1330          self._partitions,
   1331          self.common_metadata_path,
-> 1332          self.metadata_path) = _make_manifest(
   1333              path_or_paths, self._fs, metadata_nthreads=metadata_nthreads,
   1334              open_file_func=partial(_open_dataset_file, self._metadata)

~/mambaforge/envs/coiled/lib/python3.9/site-packages/pyarrow/parquet.py in _make_manifest(path_or_paths, fs, pathsep, metadata_nthreads, open_file_func)
   1577         for path in path_or_paths:
   1578             if not fs.isfile(path):
-> 1579                 raise OSError('Passed non-file path: {}'
   1580                               .format(path))
   1581             piece = ParquetDatasetPiece._create(

OSError: Passed non-file path: oss-shared-scratch/timeseries.parquet

Activity

  1. jorisvandenbossche commented on Aug 13, 2021

    @jorisvandenbossche
    Member

    From the traceback, it seems this is a problem with fs (an fsspec / s3fs filesystem) not recognizing it correctly as a file or directory (not sure which of the two would be correct?)

    Is the file publicly accessible? (or do you see something similar with a publicly accessible bucket?)

  2. jorisvandenbossche commented on Aug 13, 2021

    @jorisvandenbossche
    Member

    Also, which version of dask are you using? If not latest main branch, can you check with engine=pyarrow-dataset? (the traceback seems to indicate that you are using the legacy engine)

  3. mrocklin commented on Aug 17, 2021

    @mrocklin
    Member

    Ping @jrbourbeau to put this on his inbox in the morning.

  4. jrbourbeau commented on Aug 25, 2021

    @jrbourbeau
    MemberAuthor

    Sorry for the delayed response. Here's a minimal reproducer

    import dask
    import dask.dataframe as dd
    from dask.distributed import Client
    
    client = Client()
    
    df = dask.datasets.timeseries(
        dtypes={str(i): int for i in range(10)},
        freq="1s",
        start="1800-01-01",
        end="1800-02-01",
    )
    
    storage_options={
        "config_kwargs": {"region_name": "us-east-1"},
    }
    
    df.to_parquet(
        "s3://james-scratch/timeseries-small.parquet",
        # engine="fastparquet",
        engine="pyarrow-dataset",
        storage_options=storage_options,
        overwrite=True,
    )
    
    # import s3fs
    # s3fs.S3FileSystem.clear_instance_cache()
    
    df2 = dd.read_parquet(
        "s3://james-scratch/timeseries-small.parquet",
        # engine="fastparquet",
        engine="pyarrow-dataset",
        storage_options=storage_options,
    )
    print(df2.head())

    I've run this locally using

    • The latestmain branch of dask and distributed
    • pyarrow=5.0.0
    • fastparquet=0.7.1
    • s3fs=2021.7.0

    which produces an error with both the pyarrow-dataset and fastparquet engines (errors included below).

    pyarrow-dataset traceback:
    Traceback (most recent call last):
      File "/Users/james/Desktop/c1/test.py", line 27, in <module>
        df2 = dd.read_parquet(
      File "/Users/james/projects/dask/dask/dask/dataframe/io/parquet/core.py", line 318, in read_parquet
        read_metadata_result = engine.read_metadata(
      File "/Users/james/projects/dask/dask/dask/dataframe/io/parquet/arrow.py", line 541, in read_metadata
        ) = cls._gather_metadata(
      File "/Users/james/projects/dask/dask/dask/dataframe/io/parquet/arrow.py", line 1084, in _gather_metadata
        ds = pa_ds.dataset(
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/pyarrow/dataset.py", line 658, in dataset
        return _filesystem_dataset(source, **kwargs)
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/pyarrow/dataset.py", line 410, in _filesystem_dataset
        return factory.finish(schema)
      File "pyarrow/_dataset.pyx", line 2402, in pyarrow._dataset.DatasetFactory.finish
      File "pyarrow/error.pxi", line 143, in pyarrow.lib.pyarrow_internal_check_status
      File "pyarrow/_fs.pyx", line 1086, in pyarrow._fs._cb_open_input_file
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/pyarrow/fs.py", line 319, in open_input_file
        raise FileNotFoundError(path)
    FileNotFoundError: james-scratch/timeseries-small.parquet
    fastparquet traceback:
    Traceback (most recent call last):
      File "/Users/james/Desktop/c1/test.py", line 31, in <module>
        df2 = dd.read_parquet(
      File "/Users/james/projects/dask/dask/dask/dataframe/io/parquet/core.py", line 318, in read_parquet
        read_metadata_result = engine.read_metadata(
      File "/Users/james/projects/dask/dask/dask/dataframe/io/parquet/fastparquet.py", line 758, in read_metadata
        parts, pf, gather_statistics, base_path = _determine_pf_parts(
      File "/Users/james/projects/dask/dask/dask/dataframe/io/parquet/fastparquet.py", line 209, in _determine_pf_parts
        pf = ParquetFile(
      File "/Users/james/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/fastparquet/api.py", line 159, in __init__
        raise FileNotFoundError
    FileNotFoundError

    Interestingly, I also found that:

    1. If I clear the s3fs cache between to_parquet and read_parquet calls, then everything runs as expected
    2. If I just run the read_parquet call, without the to_parquet call, then everything runs as expected.

    All this makes me think that perhaps the underlying issue has to do with s3fs, and not Dask itself. I'm not sure though, this is just a hunch. cc @martindurant

  5. martindurant commented on Aug 26, 2021

    @martindurant
    Member

    Oh no, it passes for me! :) 50MB isn't that small on my home internet.

    So probably what is happening, is that files are being written to paths within the bucket by the workers, and the s3fs instance in the client doesn't know about any change to the bucket status. So any cached file listings will become out of date, leading to the FileNotFound.

    This all suggests that any dask write operation should aggressively call .invalidate_cache on any filesystem it uses. All fsspec filesystems have this method, even if they don't maintain a listings cache. In fact, the workers should do this too, because it may happen that some worker didn't happen to write a file in some particular workload, but already had an instance with now outdated listings.

    So, we face a conflict between the potentially large savings of reusing s3 instances and caching file listings (in the client and workers) versus having to orchestrate filesystem instances across the cluster. We've thought a bit about the latter more in the context of atomicity, only finalise all the files when every task has finished; but this idea has not yet been fleshed out.

    Of course, it's possible to turn off file listings caching while still reusing instances (use_listings_cache=False). That might be an OK general recommendation for cases like this.

  6. jrbourbeau commented on Aug 26, 2021

    @jrbourbeau
    MemberAuthor

    Thanks for the additional details @martindurant, that's quite useful to know. Passing use_listings_cache=False through storage_options indeed resolves the FileNotFoundError failure in the above snippet.

    Do you have thoughts on how we should improve the current situation? We could

    • Change use_listings_cache to be False by default in fsspec (this may be an overreaction)
    • Automatically set use_listings_cache=False in Dask's storage_options (if not already specified by the user)
    • Add a bunch of invalidate_cache calls when performing write operations in Dask (I'd prefer the storage_options approach)
    • ... something else? Other suggestions are welcome

    FWIW when running parquet + S3 workloads, I came across a variety of seemingly strange errors related to caching in s3fs. I was able to look around and found some issues which said to use s3fs.S3FileSystem.clear_instance_cache(). This worked in most (maybe all?) cases, but I wouldn't expect most Dask users to hunt s3fs.S3FileSystem.clear_instance_cache() down.

  7. martindurant commented on Aug 27, 2021

    @martindurant
    Member

    Let me dump a little information here, and then we can figure out where it should be stored...

    There are FOUR kinds of cache in fsspec:

    • the instance cache (in fsspec.spec) , whereby a filesystem with a set of protocol/storage_options will not need to create a new instance every time, thus sharing any session object, connection pool, auth and the other caches below. You can clear the cache with cls.clear_instance_cache, or insist on a new instance with skip_instance_cache=True at init time.
    • file listings cache (in fsspec.dircache), for those implementations where getting file info is expensive (i.e., not local). It's just a dict of path:list(file infos). You can interact with it with fs.invalidate_cache, either with a specific path to remove, or None to clear all paths. You can set how the cache behaves with instance arguments use_listings_cache, listings_expiry_time, max_paths
    • file cache types (fsspec.implementations.cached) for storing data locally. This is the only one that can span processes via the filesystem, or even nodes if that filesystem is networked. There is a plan to allow storage to be remote too, e.g., cache files to local S3 when the originals are in another cloud/service/region. These are normally activated explicitly, by including one of the cache implementations in the url, e.g., "simplecache::s3://bucket/path"
    • bytes cache for an open/streaming file, only for those implementations where open() returns a file subclassing from fsspec.spec.AbstractBufferedFile, in fsspec.caching. There are a few of these, chosen with kwarg cache_type some with various options. These live with the file instance while it is open.

    I would argue, to your question, that clear_instance_cache is a bad idea, since you incur the cost of new connections and auth in every dask task. Either use_listings_cache=False or appropriate calls to invalidate_cache() are the reasonable choices here. Or, we could somehow make the listings cache itself smarter. Currently it only has a simple TTL, which might actually already be enough for the situation at hand.

  8. added
    needs attention
    on Oct 25, 2021
  9. jcrist commented on Apr 13, 2022

    @jcrist
    Member

    Summarizing the state of this issue, it looks like there are 2 suggested solutions:

    • Automatically set use_listings_cache=False in Dask's storage_options (if not already specified by the user)
    • Call fs.invalidate_cache() in non-read operations. (wouldn't this still not work if files were written by an external process before a read_parquet call?)

    AFAICT the former should always work but may lead to performance issues, while the latter may work but would fail if something was modified external to the process doing the listing. Is that accurate?

    A third option would be to:

    • Never use the cache when listing/globbing/... files when building the graph for a high-level (e.g. read_parquet) call on the client. This ensures all files are always found when setting up a graph for a read.
    • Invalidate the cache after any write operation on the workers
    • Continue to use the default cache behavior on read

    I think this would be sufficient - the generated graph would always contain all files, and it would let caching on the workers still work during reads for any performance benefits that may have (are there any for read calls?).

    If this more complicated third option doesn't get us anything, I'd opt for the first option, as it's simple to implement. @martindurant can you add some color into the performance impacts we might see from disabling caching using the strategies above? Should we worry about such a change?

  10. self-assigned this
    on Apr 14, 2022
  11. jcrist commented on Apr 27, 2022

    @jcrist
    Member

    @martindurant can you add some color into the performance impacts we might see from disabling caching using the strategies above? Should we worry about such a change?

    @martindurant , if you have a moment I'd appreciate some fsspec advice here ^^

  12. martindurant commented on Apr 27, 2022

    @martindurant
    Member

    Listing files on s3 can be slow, because a limited number of files are returned in each call (with a surprising amount of bytes, due to XML encoding and lots of details), and you need to paginate through serially. Since we are explicitly moving towards a no _metadata and many datafiles in many directories model, this cost will be bigger in the future. You would notice not caching particularly if you had reason to dd.read_parquet multiple times on the same dataset, perhaps because you want to try different options.

    (If there were a _metadata, there would be no need to list at all. Of course, my intuition might be out of date by now...)

    Call fs.invalidate_cache() in non-read operations. (wouldn't this still not work if files were written by an external process before a read_parquet call?)

    Correct, you can always have stale info when files are modified in another process. If all you want to do is open a file with known path, that's probably always fine, so this only matters on the client. Which argues that it doesn't matter much whether you have it on the workers.

    One note: sharing FS instances is good for cutting the cost of establishing connections/credentials; if the uses has one they are using to list files and find their data, with the default listings cache, and we choose to make a another one without, then it will be a separate instance and session. This point argues (weakly) towards invalidating the cache rather than disabling it.

  13. jcrist commented on Apr 27, 2022

    @jcrist
    Member

    Based on your comment above, I think the 2nd option (call fs.invalidate_cache() in non-read operations) might make the most sense then? We'd have to_parquet invalidate the local (client side) cache before returning. This gets a bit weird if compute=False, but I think it's still what we want to do. This would solve the specific issue here, and shouldn't be too costly in the normal case. I also think we wouldn't need to call invalidate_cache ever on the workers, since the real issue here is with listings and those never happen on the workers?

  14. martindurant commented on Apr 27, 2022

    @martindurant
    Member

    The workers should invalidate their cache for the specific directory they are writing into anyway. So yes, agreed.

  15. jcrist commented on Apr 28, 2022

    @jcrist
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dataframeioneeds attentionparquet

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions