Repository navigation
Refactor read_metadata in pyarrow parquet engines - #8072
Conversation
|
rerun tests |
This PR fixes some un-tested hive-partitioning edge cases in read-parquet. The "full" fix requires [dask#8072](dask/dask#8072). However, this PR should be merged before the upstream change goes in (otherwise dask_cudf.read_parquet CI will temporarily break). Note that this change is non-breaking, but the corresponding dask-dataframe change **is**. Authors: - Richard (Rick) Zamora (https://github.com/rjzamora) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) - Benjamin Zaitlen (https://github.com/quasiben) URL: #9122
|
@martindurant - This PR doesn't include any fastparquet-engine changes, but the follow-up PR (#8092) does (and it follows pretty much the same pattern). At this point, the PRs are getting a bit old (and are making it hard for me to focus on other Dask-parquet bug-fixes/improvements). It would be great to get your eyes on both PRs if you find the time. I also welcome other reviewers who might be interested :) Note that I do feel relatively confident that this PR is "low-risk". There is not a lot of new logic, and that logic is only used in the case that a global _metadata file is missing. With that said, it is a complete arrow-engine implementation of the plan in #8058, and so the diff is still quite large. |
martindurant
left a comment
There was a problem hiding this comment.
Here are comments from the diff alone - mostly questions.
I will go through the code on the branch in detail too, but I don't think that should be a blocker.
|
|
||
| # Main parts/stats-construction | ||
| if has_metadata_file or metadata_task_size == 0: | ||
| # We have a global _metadata file to work with. |
There was a problem hiding this comment.
if metadata_task_size is 0, we are not bothering with stats at all, right?
There was a problem hiding this comment.
No. metadata_task_size=0 just means that we will not use parallel metadata collection. If the user still needs statistics (e.g. for filtering), then we will still collect/process them in serial.
| all_files = [ | ||
| filef | ||
| for filef in all_files | ||
| if filef.split(fs.sep)[-1] in valid_paths |
There was a problem hiding this comment.
Why only the last path element?
There was a problem hiding this comment.
This is not new code, but I'm sure it could be simplified in a simple stand-alone PR. We are essentially comparing the file names to a list of "valid" filenames that have not been filtered out during dataset discovery. We only take the last element, because that is the file name.
| stats += stat | ||
| return parts, stats | ||
|
|
||
| gather_parts_dsk["final-" + name] = (_combine_parts, finalize_list) |
There was a problem hiding this comment.
It's actually quite HLG-ish. Shouldn't matter here.
There was a problem hiding this comment.
Are you suggesting that this could be an HLG layer?
| cmin = statistics[name]["min"] | ||
| cmax = statistics[name]["max"] | ||
| last = cmax_last.get(name, None) | ||
| if not (filters or chunksize or aggregation_depth): |
There was a problem hiding this comment.
It feels like there are cases in which we can skip this whole set of loops altogether
There was a problem hiding this comment.
Can you elaborate? This nested loop is indeed a bit much, but I've found it surprisingly challenging to improve.
rjzamora
left a comment
There was a problem hiding this comment.
Thanks for taking the time to slog through this @martindurant !
I left some temporary responses to your comments, and I'll try to address whatever I can tonight.
| if file_frag is not None: | ||
| # Check/correct order of `categories` using last file_frag | ||
| # | ||
| # Note that `_get_partition_keys` does NOT preserve the |
There was a problem hiding this comment.
I would be pretty far from surprised to learn that the curent workaround is not the most efficient solution. In fact, knowing myself, am a bit confused why I would have used re before trying a simple split. In either case, I will try simplifying this a bit. Note that fastparquet does not require this workaround at all.
| # - "partitioning_method" : (dict) The `partitioning` options | ||
| # used for file discovory by pyarrow. | ||
| # | ||
| return { |
There was a problem hiding this comment.
Ar you referring to to the returned datset_info dict, or the "partitioning information" discuessed just above?
|
|
||
| # Main parts/stats-construction | ||
| if has_metadata_file or metadata_task_size == 0: | ||
| # We have a global _metadata file to work with. |
There was a problem hiding this comment.
No. metadata_task_size=0 just means that we will not use parallel metadata collection. If the user still needs statistics (e.g. for filtering), then we will still collect/process them in serial.
| all_files = [ | ||
| filef | ||
| for filef in all_files | ||
| if filef.split(fs.sep)[-1] in valid_paths |
There was a problem hiding this comment.
This is not new code, but I'm sure it could be simplified in a simple stand-alone PR. We are essentially comparing the file names to a list of "valid" filenames that have not been filtered out during dataset discovery. We only take the last element, because that is the file name.
| stats += stat | ||
| return parts, stats | ||
|
|
||
| gather_parts_dsk["final-" + name] = (_combine_parts, finalize_list) |
There was a problem hiding this comment.
Are you suggesting that this could be an HLG layer?
| cmin = statistics[name]["min"] | ||
| cmax = statistics[name]["max"] | ||
| last = cmax_last.get(name, None) | ||
| if not (filters or chunksize or aggregation_depth): |
There was a problem hiding this comment.
Can you elaborate? This nested loop is indeed a bit much, but I've found it surprisingly challenging to improve.
| parquet: | ||
| metadata-task-size-local: 512 # Number of files per local metadata-processing task | ||
| metadata-task-size-remote: 16 # Number of files per remote metadata-processing task |
There was a problem hiding this comment.
Okay - Did a fair bit of local testing to confirm that tese are reasonable defaults. Note that I also tweaked the logic so that the parallel metadata processing will not kick in unless the number of files exceeds this number.
A similar fix for this problem was recently submitted in #9159 and closed in favor of #9203. It seems that the test added in the latter PR was not actually capturing the original problem. However, after [dask#8072](dask/dask#8072) is merged, the new test will certainly start failing. Authors: - Richard (Rick) Zamora (https://github.com/rjzamora) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) - Benjamin Zaitlen (https://github.com/quasiben) URL: #9314
|
@dask/io - Please let me know if anyone has plans to review this PR in the near future. If not, I think it may be best to merge at the end of the day so I can shift my focus to #8092 (and other fixes/improvements). |
|
I am +1 for merge and iterate |
|
I created a notebook with some benchmarks (using a version of Dask before this was merged). This takes 1 second: ddf = dd.read_parquet(
"s3://coiled-datasets/timeseries/20-years/parquet",
storage_options={"anon": True, "use_ssl": True},
ignore_metadata_file=False,
split_row_groups=True,
engine="pyarrow",
)This takes 210 seconds: ddf2 = dd.read_parquet(
"s3://coiled-datasets/timeseries/20-years/parquet",
storage_options={"anon": True, "use_ssl": True},
ignore_metadata_file=True,
split_row_groups=True,
engine="pyarrow",
)Once a new version of Dask is released, I'll quantify gains and see how much faster Great work @rjzamora! |
This is a follow-up to #8034, and corresponds to the "short-term"
ArrowDatasetEnginecomponent of the plan discussed in #8058 .Currently, when the user specifies
ignore_metadata_file=True(or if the_metadatafile is missing) the logic inArrowDatasetEngine.read_metadatawill construct a read-parquet "plan" by iterating through every file in the dataset (in serial). With the changes in this PR, the output-partitioning plan will be executed in parallel. In order to expose control over this algorithm to the user, afiles_per_metadata_taskargument was added. This argument allows the user to specify how many distinct paths should ne processed within the same parquet-metadata-processing task. Iffiles_per_metadata_task=0, parallel metadata-processing is dissabled.Note that the
PyarrowLegacyEnginecode was also refactored here, but the changes in that engine fall short of supporting parallel parquet-metadata processing.