Skip to content

Dask fails to read hand-partitioned Parquet dataset from S3 source #6713

Closed

Description

@ResidentMario

I created a Parquet dataset partitioned as follows:

2019-taxi-trips/
    - month=1/
        - data.parquet
    - month=2/
        - data.parquet
    ...
    - month=12/
        - data.parquet

This organization follows the Parquet dataset partitioning convention used by Hive Metastore. This partitioning scheme was generated by hand, so there is no _metadata file anywhere in the directory tree.

I would like to now read this dataset into Dask.

With data located on local disk, the following code works:

import dask.dataframe as dd
dd.read_parquet(
    "/Users/alekseybilogur/Desktop/2019-taxi-trips/*/data.parquet",
    engine="fastparquet"
)

I copied these files to an S3 bucket (via s3 sync; partition folders are top level keys in the bucket, like so), and attempted to read them off of cloud storage using the same basic function:

import dask.dataframe as dd; dd.read_parquet(
    "s3://2019-nyc-taxi-trips/*/data.parquet",
    storage_options={
        "key": "...",
        "secret": "..."
    },
    engine="fastparquet")

This raises IndexError: list index out of range. Full stack trace here.


I originally filed this as a Stack Overflow question, @martindurant suggested that this was probably a bug and should be filed here instead, so I've done that now.

Activity

  1. martindurant commented on Oct 8, 2020

    @martindurant
    Member

    Note that I expect the following workaround to work:

    • use s3fs to glob the path "2019-nyc-taxi-trips/*/data.parquet"
    • pass this list of paths (with "s3://" prefix) to read_parquet.

    Probably fastparquet itself ought to be aware of glob strings, but its API predates fsspec, and it expects only the open function of the filesystem, not the filesystem itself.

  2. hhuuggoo commented on Oct 9, 2020

    @hhuuggoo

    @ResidentMario, @martindurant on a related note, support for parquet filters that understand parquet dataset partitioning is very useful. In situations where there are large number of parquet files, s3fs globs can be a big bottleneck. The pyarrow backend supports this pretty well. I've been able to read datasets as follows:

    dd.read_parquet(
        "s3://2019-nyc-taxi-trips/*/data.parquet",
        storage_options={
            "key": "...",
            "secret": "..."
        },
        filters=[("month", "=", "1")],
        engine="pyarrow"
    )
    
  3. ResidentMario commented on Oct 9, 2020

    @ResidentMario
    Author

    @hhuuggoo this is an unrelated question, but for my own knowledge. I also attempted to read these files using pyarrow, using pretty much the same code sample you show here, and was blocked on a "pyarrow not compiled with S3 support" error message.

    How did you get a version of pyarrow that supports S3? Did you compile pyarrow yourself?

  4. martindurant commented on Oct 9, 2020

    @martindurant
    Member

    pyarrow should not need s3 support internally, as dask passes an s3fs file system object to it. Can you specify what you have installed on your system and how you got to that error?

  5. hhuuggoo commented on Oct 9, 2020

    @hhuuggoo

    @hhuuggoo this is an unrelated question, but for my own knowledge. I also attempted to read these files using pyarrow, using pretty much the same code sample you show here, and was blocked on a "pyarrow not compiled with S3 support" error message.

    How did you get a version of pyarrow that supports S3? Did you compile pyarrow yourself?

    I'm pretty sure I'm just using the pyarrow conda package, so nothing special on my end

  6. martindurant commented on Oct 9, 2020

    @martindurant
    Member

    @jorisvandenbossche , have people been seeing this? Perhaps with the arrow filesystem migration?

  7. ResidentMario commented on Oct 9, 2020

    @ResidentMario
    Author

    @martindurant You are correct. The following code sample works:

    dd.read_parquet(
        "s3://2019-nyc-taxi-trips/*/data.parquet",
        storage_options={
            "key": "...",
            "secret": "..."
        },
        engine="pyarrow"
    )

    The following code sample, which uses the pyarrow directly, fails:

    import pyarrow.dataset as ds
    dataset = ds.dataset("s3://2019-taxi-trips/*/data.parquet", format="parquet", partitioning="hive")
    
    ArrowNotImplementedError: Got S3 URI but Arrow compiled without S3 support

    It is not transparent to me why one would work and the other would fail. ¯\_(ツ)_/¯

  8. martindurant commented on Oct 9, 2020

    @martindurant
    Member

    In the latter you are asking pyarrow to create its own filesystem type, and it doesn't know about fsspec directly. You can pass the (s3fs) filesystem object to ds.dataset, which is what Dask does internally.

    fs = fsspec.filesystem("s3", key=, secret=)
    dataset = ds.dataset(
        "s3://2019-taxi-trips/*/data.parquet", format="parquet", 
        partitioning="hive", filesystem=fs
    )
    
  9. ResidentMario commented on Oct 9, 2020

    @ResidentMario
    Author

    Oh interesting! So the error message is merely a bit misleading/ambiguous then, got it, ty ty.

  10. martindurant commented on Oct 9, 2020

    @martindurant
    Member

    I wouldn't call it ambiguous or misleading, but perhaps incomplete :)

  11. jorisvandenbossche commented on Nov 23, 2020

    @jorisvandenbossche
    Member

    Late answer here, but indeed pyarrow itself doesn't use or fallback to fsspec, and by default only uses its own filesystems (unless you pass it explicitly a filesystem object, like @martindurant showed).

    Pyarrow includes an S3 filesystem implementation, but, the support for this in the wheels is a bit varying (AFAIK, wheels for windows lack support for this, and for Mac OSX support was only added in the wheels for the 2.0 release; conda packages for all platforms and linux wheels should be fine). So I suppose that is the reason you saw that error message ("Got S3 URI but Arrow compiled without S3 support"), which by itself is thus correct, but I certainly understand that this is confusing if you don't know the broader picture..

  12. ResidentMario commented on Nov 23, 2020

    @ResidentMario
    Author

    Well, to be honest, this isn't my first attempt to use pyarrow for something, and not my first time running into an opaque (to me) issue like this getting in the way. I'm sure it's a very powerful tool if you know how to use it but...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions