-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
fs, storage_options, kwargs.pop("open_file_options", {}) | ||
) | ||
|
||
# Stage 1: Collect general dataset information | ||
dataset_info = cls._collect_dataset_info( | ||
paths, | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
"""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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is dumb, but rather than build this convention, could we do something like ...
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)