Skip to content

Use new efficient partitioned parquet writing in cuDF - #9971

Merged
rapids-bot[bot] merged 60 commits into
NVIDIA:branch-22.02from
devavret:py-parq-partitioned-write
Jan 10, 2022
Merged

rapids-bot[bot] merged 60 commits into
NVIDIA:branch-22.02from
devavret:py-parq-partitioned-write

Conversation

@devavret

@devavret devavret commented Jan 4, 2022

Copy link
Copy Markdown
Contributor

Makes use of the efficient partitioned writing support added in #9810 to improve performance of partitioned parquet dataset writing.

Closes #5059

Exception raised by writer needs to be same as that raised by pandas.
If user_data is constructed earlier using pyarrow then the exception is
raised early and is different
@github-actions github-actions Bot added Python Affects Python cuDF API. libcudf Affects libcudf (C++/CUDA) code. labels Jan 4, 2022
@devavret devavret added 4 - Needs cuDF (Python) Reviewer cuIO cuIO issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jan 4, 2022
@vuule

vuule commented Jan 5, 2022

Copy link
Copy Markdown
Contributor

Do we have any benchmarks for this?

@vuule vuule left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

C++ looks good :)
Super curious about the perf gain from this change!

@devavret

devavret commented Jan 5, 2022

Copy link
Copy Markdown
Contributor Author

C++ looks good :) Super curious about the perf gain from this change!

Here's the nsys profiles:
1.3s -> 730ms
Screenshot 2022-01-05 at 5 23 11 PM (3)
Screenshot 2022-01-05 at 6 18 56 PM

Comment on lines +45 to +67
paths_or_bufs = [
ioutils.get_writer_filepath_or_buffer(path, mode="wb", **kwargs)
for path in paths
]
common_args = {
"index": index,
"compression": compression,
"statistics": statistics,
"metadata_file_path": metadata_file_path,
"int96_timestamps": int96_timestamps,
"row_group_size_bytes": row_group_size_bytes,
"row_group_size_rows": row_group_size_rows,
"partitions_info": partitions_info,
}
if all([ioutils.is_fsspec_open_file(buf) for buf in paths_or_bufs]):
with ExitStack() as stack:
fsspec_objs = [stack.enter_context(file) for file in paths_or_bufs]
file_objs = [
ioutils.get_IOBase_writer(file_obj) for file_obj in fsspec_objs
]
write_parquet_res = libparquet.write_parquet(
df, filepaths_or_buffers=file_objs, **common_args
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Python reviewers, is this an appropriate replacement for https://github.com/rapidsai/cudf/blob/ba3aedbb869ef95cae517f56ffb2bab305bffa40/python/cudf/cudf/io/parquet.py#L702-L708

Note that because we want to open multiple files to write to them at the same time, I couldn't use with.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is reasonable.

@codecov

codecov Bot commented Jan 5, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #9971 (5b00973) into branch-22.02 (967a333) will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff                @@
##           branch-22.02    #9971      +/-   ##
================================================
- Coverage         10.49%   10.44%   -0.05%     
================================================
  Files               119      119              
  Lines             20305    20430     +125     
================================================
+ Hits               2130     2134       +4     
- Misses            18175    18296     +121     
Impacted Files Coverage Δ
python/custreamz/custreamz/kafka.py 29.16% <0.00%> (-0.63%) ⬇️
python/dask_cudf/dask_cudf/sorting.py 92.30% <0.00%> (-0.61%) ⬇️
python/cudf/cudf/__init__.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/frame.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/index.py 0.00% <0.00%> (ø)
python/cudf/cudf/io/parquet.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/series.py 0.00% <0.00%> (ø)
python/cudf/cudf/utils/utils.py 0.00% <0.00%> (ø)
python/cudf/cudf/utils/dtypes.py 0.00% <0.00%> (ø)
python/cudf/cudf/utils/ioutils.py 0.00% <0.00%> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4dc42d...5b00973. Read the comment docs.

Comment thread python/cudf/cudf/_lib/io/utils.pyx Resolved
Comment thread python/cudf/cudf/_lib/io/utils.pyx Resolved
Comment thread python/cudf/cudf/_lib/io/utils.pyx Resolved
Comment thread python/cudf/cudf/_lib/io/utils.pyx Resolved
Comment thread python/cudf/cudf/_lib/parquet.pyx Resolved
Comment on lines +45 to +67
paths_or_bufs = [
ioutils.get_writer_filepath_or_buffer(path, mode="wb", **kwargs)
for path in paths
]
common_args = {
"index": index,
"compression": compression,
"statistics": statistics,
"metadata_file_path": metadata_file_path,
"int96_timestamps": int96_timestamps,
"row_group_size_bytes": row_group_size_bytes,
"row_group_size_rows": row_group_size_rows,
"partitions_info": partitions_info,
}
if all([ioutils.is_fsspec_open_file(buf) for buf in paths_or_bufs]):
with ExitStack() as stack:
fsspec_objs = [stack.enter_context(file) for file in paths_or_bufs]
file_objs = [
ioutils.get_IOBase_writer(file_obj) for file_obj in fsspec_objs
]
write_parquet_res = libparquet.write_parquet(
df, filepaths_or_buffers=file_objs, **common_args
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is reasonable.

@devavret
devavret requested a review from galipremsagar January 7, 2022 14:47
@isVoid
isVoid removed their request for review January 7, 2022 17:38

@rjzamora rjzamora left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is exciting @devavret - Thanks for working on this!

I left a few minor comments, but the general suggestion is to update the to_parquet docstring to explain the new kwarg(s).

Comment thread python/cudf/cudf/io/parquet.py Resolved
Comment thread python/cudf/cudf/io/parquet.py Resolved
Comment on lines +714 to +718
if metadata_file_path is not None:
warnings.warn(
"metadata_file_path will be ignored/overwritten when "
"partition_cols are provided"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you explain this? It seems like there may be a significant change in behavior here. If so, the behavior should probably be described in the docstring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah - I see. This is a consequence of the ugly circular logic between to_parquet and write_to_dataset. Some historical context: I believe write_to_dataset was originally inteded to be the only way to write out a partitioned dataset. However, partition_cols was later added to to_parquet to redirect back into write_to_dataset. The problem with this latter approach is that you can no longer specify metadata_file_path. Instead, the user must specify return_metadata=True if they want the final metadata object to be returned.

Perhaps we need to add the return_metadata kwarg to the to_parquet docstring to make this clearer? Either way, the warning above should probably suggest using return_metadata=True if the user tries specifying metadata_file_path. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The problem created by this PR is that now there are two ways to get partitioning with to_parquet. The first is to pass partition_cols and partition_file_name and let cudf figure out the partitions and directory structure. The other is to pass a list of paths, offsets into the df to partition by and list of metadata_file_paths to set to each partition.

The second method is not really intended to be used by users and I worry that someone might think to pass args for both and get confused.

Comment thread python/cudf/cudf/io/parquet.py Resolved
@devavret
devavret requested a review from rjzamora January 7, 2022 23:16

@rjzamora rjzamora left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - Thanks @devavret !

@devavret

Copy link
Copy Markdown
Contributor Author

@gpucibot merge

@rapids-bot
rapids-bot Bot merged commit bb3844e into NVIDIA:branch-22.02 Jan 10, 2022
@vyasr vyasr added 4 - Needs Review Waiting for reviewer to review or respond and removed 4 - Needs cuDF (Python) Reviewer labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4 - Needs Review Waiting for reviewer to review or respond cuIO cuIO issue improvement Improvement / enhancement to an existing function libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA] Efficient partition_cols for parquet writer

5 participants