Skip to content

Unable to read partitioned Parquet dataset from S3 without metadata present #6782

Closed

Description

@kinghuang

What happened:

I unloaded (exported) a Parquet dataset from an AWS Redshift database. The data is partitioned by year and month with Hive-style partitions. When I attempt to read this using Dask, I'm getting an IndexError.

What you expected to happen:

I expect to be able to read the Parquet dataset using Dask. Strangely, if I specify any one of the months to read, Dask is able to read it succesfully. But, once a partition path is involved, the IndexError occurs.

Minimal Complete Verifiable Example:

The data resides in S3, and is laid out like so. The key prefix here has been obfuscated, but the end object names are as they appear from Redshift.

s3://bucket/data/year=2018/month=1/0000_part_00.parquet
s3://bucket/data/year=2018/month=1/0001_part_00.parquet
s3://bucket/data/year=2018/month=1/0002_part_00.parquet
s3://bucket/data/year=2018/month=1/0003_part_00.parquet
s3://bucket/data/year=2018/month=2/0000_part_00.parquet
s3://bucket/data/year=2018/month=2/0001_part_00.parquet
s3://bucket/data/year=2018/month=2/0002_part_00.parquet
s3://bucket/data/year=2018/month=2/0003_part_00.parquet
…
s3://bucket/data/year=2020/month=10/0003_part_00.parquet

The dataset consists of partitions from year=2018/month=1 to year=2020/month=10. There are no metadata files (_metadata or _common_metadata).

Reading the individual parquet objects or a whole month works, if written like so. This effectively means that there's no partitions.

from dask import dataframe as dd

df = dd.read_parquet("s3://bucket/data/year=2018/month=1/0000_part_00.parquet")  # works
df = dd.read_parquet("s3://bucket/data/year=2018/month=1")  # also works

The following fails, when there are partitions to be picked up from the path/prefix.

df = dd.read_parquet("s3://bucket/data")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/core.py", line 231, in read_parquet
    meta, statistics, parts, index = engine.read_metadata(
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 655, in read_metadata
    ) = _gather_metadata(
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 166, in _gather_metadata
    dataset, base, fns = _get_dataset_object(paths, fs, filters, dataset_kwargs)
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 143, in _get_dataset_object
    base, fns = _analyze_paths(allpaths, fs)
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/utils.py", line 407, in _analyze_paths
    basepath = path_parts_list[0][:-1]
IndexError: list index out of range

Providing a filter doesn't help.

df = dd.read_parquet("s3://bucket/data", filters=[[("year", "=", "2018"), ("month", "=", "1")]])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/core.py", line 231, in read_parquet
    meta, statistics, parts, index = engine.read_metadata(
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 655, in read_metadata
    ) = _gather_metadata(
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 166, in _gather_metadata
    dataset, base, fns = _get_dataset_object(paths, fs, filters, dataset_kwargs)
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 143, in _get_dataset_object
    base, fns = _analyze_paths(allpaths, fs)
  File "/usr/local/lib/python3.8/site-packages/dask/dataframe/io/parquet/utils.py", line 407, in _analyze_paths
    basepath = path_parts_list[0][:-1]
IndexError: list index out of range

Reading a partitioned dataset with metadata present does work.

Anything else we need to know?:

Using a glob pattern to pick up all the underlying Parquet objects works. But, then the resulting dataframe is missing the partition columns (year and month).

df = dd.read_parquet("s3://bucket/data/*/*/*.parquet")

print(df.columns)  # missing columns for the year and month partitions

This feels like it's the same problem as #6713. I've verified that I'm the owner and have permissions for all the S3 objects to be read.

Environment:

  • Dask version: 2.30.0
  • Python version: 3.8.6
  • Operating System: Linux ec13c33877e5 5.4.39-linuxkit (python:3.8 Docker image)
  • Install method (conda, pip, source): pip

Activity

  1. kinghuang commented on Oct 31, 2020

    @kinghuang
    Author

    Did a little bit of digging. The problem appears to be

    allpaths = fs.glob(paths[0] + fs.sep + "*")

    Using s3fs directly for testing, I get an empty list back for the glob.

    import s3fs
    
    s3fs.glob("bucket/data/*")
    []

    Using ls works.

    s3fs.ls("bucket/data/")
    ['bucket/data/year=2018', 'bucket/data/year=2019', 'bucket/data/year=2020']

    If I change the aforementioned code line (utils.py, line 142) to the following, I am able to load my partitioned dataset with Dask.

            allpaths = fs.ls(paths[0] + fs.sep)
    df = dd.read_parquet("s3://bucket/data/")  # this now works, and I have the partitions as columns

    I'm not sure what impact such a change will have on non-S3 sources.

  2. jsignell commented on Nov 5, 2020

    @jsignell
    Member

    Sorry for slow response @kinghuang. I think that the multiple levels of directory nesting is causing issues. The workaround that you propose is the right way forward.

    df = dd.read_parquet("s3://bucket/data/*/*/*.parquet")
    
    print(df.columns)  # missing columns for the year and month partitions

    The year and month data are not meant to be included in the output when you use IO-level filters. Although this might be a nice feature to add.

    Pinging @martindurant since I can't quite tell if there is an fsspec bug. This line seems to stop recursion: https://github.com/intake/filesystem_spec/blob/f57fddbe23c72aae4643d86022cf2e314c9b51ee/fsspec/core.py#L626

  3. martindurant commented on Nov 5, 2020

    @martindurant
    Member

    Sorry, @jsignell , what are you asking me?

    For paths/glob stuff, it may well be worth trying with s3fs at current master.

    For the record, I thought that the pyarrow driver was supposed to walk the directories itself; but perhaps that's a coming feature too.

  4. kinghuang commented on Nov 5, 2020

    @kinghuang
    Author

    It seems to me that pyarrow does walk the directories itself. The problem here is that s3fs.glob("bucket/data/*") doesn't return the next level of key prefixes, whereas s3fs.ls("bucket/data/") does (see my second comment).

    Given ['bucket/data/year=2018', 'bucket/data/year=2019', 'bucket/data/year=2020'], pyarrow does correctly pick up all the partitions and everything works as expected. At the moment, the glob returns nothing, and so there is nothing to pass to pyarrow.

  5. jsignell commented on Nov 5, 2020

    @jsignell
    Member

    Sorry yeah that was unclear. I meant that that line in fsspec seems to prevent directories from being included in the output. Which I think is leading to a list of empty paths in dask here:

    fs, _, paths = get_fs_token_paths(path, mode="rb", storage_options=storage_options)

    Since the path only contains directories.

  6. martindurant commented on Nov 5, 2020

    @martindurant
    Member

    I see. The original glob("path/*") does seem to work correctly, but get_fs_token_paths gets files only. I still don't see how that's the problem, though: if pyarrow doesn't walk the tree, passing any a number of subdirectories will not help any more than passing the root directory. Pyarrow doesn't call get_fs_token_paths, so how do we get there? I recommend turning on s3fs logging (e.g., S3FS_LOGGING_LEVEL=DEBUG) to see what calls are being made.

  7. jsignell commented on Nov 6, 2020

    @jsignell
    Member

    Sorry I think I misunderstood what was going on. @kinghuang what version of fsspec are you using?

    As a side note, it is difficult to diagnose this issue without a reproducible example, so the best way to get help is to create one.

  8. jorisvandenbossche commented on Nov 9, 2020

    @jorisvandenbossche
    Member

    @kinghuang There are currently some bugs when using the latest s3fs and pyarrow (https://issues.apache.org/jira/browse/ARROW-10473, https://issues.apache.org/jira/browse/ARROW-10433 on the pyarrow side, and eg fsspec/s3fs#378 on the s3fs side (fixed in master but not yet released)).

    So could you check if it is working fine with s3fs 0.4 ?
    Or otherwise you would need s3fs master + pyarrow master (with patch from apache/arrow#8557)

    (another alternative might be s3fs master with pyarrow 1.0, but didn't check this)

  9. kinghuang commented on Nov 16, 2020

    @kinghuang
    Author

    I have fsspec==0.8.4.

    Using s3fs==0.4.2 seems ok for now.

  10. jorisvandenbossche commented on Aug 9, 2021

    @jorisvandenbossche
    Member

    The several issues I mentioned above should all be resolved I think, so it would be good to check if this is still a problem with the latest versions of s3fs / fsspec / pyarrow.

  11. kinghuang commented on Aug 9, 2021

    @kinghuang
    Author

    I'll give my Redshift data a try and report back.

  12. kinghuang commented on Aug 9, 2021

    @kinghuang
    Author

    Everything's working on the Redshift exports with the following modules:

    Package                Version
    ---------------------- -----------
    dask                   2021.7.2
    fsspec                 2021.7.0
    pyarrow                5.0.0
    s3fs                   2021.7.0
    
  13. jorisvandenbossche commented on Aug 9, 2021

    @jorisvandenbossche
    Member

    Thanks for checking!
    I think this issue can be closed then?

  14. kinghuang commented on Aug 9, 2021

    @kinghuang
    Author

    Yup, this can be closed. Thanks!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions