Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyarrow S3 file system at read time for arrow parquet engine #9669

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions dask/dataframe/io/parquet/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,15 @@ def read_metadata(
ignore_metadata_file=False,
metadata_task_size=0,
parquet_file_extension=None,
storage_options=None,
**kwargs,
):

# Set default open_file_options for remote filesystems
kwargs["open_file_options"] = cls._default_open_file_options(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_open_file_options

Maybe this is dumb, but rather than build this convention, could we do something like ...

if engine == "pyarrow" and filename.startswith("s3://") and not storage_options:
    open_file_options[...] = ...

Building a convention like _get_open_file_options for this seems a bit heavyweight to me.

(please feel free to entirely ignore this comment. I also may not ever respond. Please do not block on me)

fs, storage_options, kwargs.pop("open_file_options", {})
)

# Stage 1: Collect general dataset information
dataset_info = cls._collect_dataset_info(
paths,
Expand Down Expand Up @@ -762,6 +768,30 @@ def write_metadata(cls, parts, meta, fs, path, append=False, **kwargs):
# Private Class Methods
#

@classmethod
def _default_open_file_options(cls, fs, storage_options, input_options):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: I agree with Matt that it'd be nice to inline this logic, since it's relatively straightward and only used in one place. However, my guess is inlining this logic will make it more difficult to test. If that's the case, then I think testability should take priority.

EDIT: moving to small, private utility function seems lighter weight than a @classmethod and should make it easier to test

"""Set default open_file_options

Stick with user-provided options (if there are any). Otherwise:
Use native pyarrow filesystem for 'open_file_func' if possible.

Currently supports ``s3fs`` -> ``pyarrow.fs.S3FileSystem``.
"""
if "s3" in fs.protocol and not input_options:
pa_option_map = {"anon": "anonymous"}
try:
from pyarrow import fs as pa_fs

pa_options = {pa_option_map[k]: v for k, v in storage_options.items()}
return {
"open_file_func": pa_fs.S3FileSystem(**pa_options).open_input_file
}
except KeyError:
# Could not map one or more ``storage_options``
# keys to ``S3FileSystem`` options
pass
return input_options

@classmethod
def _collect_dataset_info(
cls,
Expand Down
1 change: 1 addition & 0 deletions dask/dataframe/io/parquet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def read_parquet(
ignore_metadata_file=ignore_metadata_file,
metadata_task_size=metadata_task_size,
parquet_file_extension=parquet_file_extension,
storage_options=storage_options,
**kwargs,
)

Expand Down
1 change: 1 addition & 0 deletions dask/dataframe/io/parquet/fastparquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ def read_metadata(
ignore_metadata_file=False,
metadata_task_size=None,
parquet_file_extension=None,
storage_options=None,
**kwargs,
):

Expand Down