Repository navigation
Description
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 worksThe 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 rangeProviding 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 rangeReading 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 partitionsThis 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
kinghuang commentedon Oct 31, 2020
Did a little bit of digging. The problem appears to be
dask/dask/dataframe/io/parquet/arrow.py
Line 142 in f1bdccb
Using
s3fsdirectly for testing, I get an empty list back for the glob.Using
lsworks.If I change the aforementioned code line (utils.py, line 142) to the following, I am able to load my partitioned dataset with Dask.
I'm not sure what impact such a change will have on non-S3 sources.
jsignell commentedon Nov 5, 2020
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.
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
martindurant commentedon Nov 5, 2020
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.
kinghuang commentedon Nov 5, 2020
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, whereass3fs.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.jsignell commentedon Nov 5, 2020
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:
dask/dask/dataframe/io/parquet/core.py
Line 296 in 3bd6bb2
Since the path only contains directories.
martindurant commentedon Nov 5, 2020
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.
jsignell commentedon Nov 6, 2020
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.
jorisvandenbossche commentedon Nov 9, 2020
@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)
kinghuang commentedon Nov 16, 2020
I have
fsspec==0.8.4.Using
s3fs==0.4.2seems ok for now.jorisvandenbossche commentedon Aug 9, 2021
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.
kinghuang commentedon Aug 9, 2021
I'll give my Redshift data a try and report back.
kinghuang commentedon Aug 9, 2021
Everything's working on the Redshift exports with the following modules:
jorisvandenbossche commentedon Aug 9, 2021
Thanks for checking!
I think this issue can be closed then?
kinghuang commentedon Aug 9, 2021
Yup, this can be closed. Thanks!