-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement row group pruning with stats in experimental PQ reader #18543
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
Merged
rapids-bot
merged 33 commits into
rapidsai:branch-25.06
from
mhaseeb123:fea/filter-row-groups-with-stats
May 6, 2025
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4f2da1f
Add hybrid scan reader stubs
mhaseeb123 343176f
Minor style and docs fix
mhaseeb123 46d7d11
docstring updates
mhaseeb123 67ac400
Add more stubs
mhaseeb123 173ed02
Remove unneeded definitions
mhaseeb123 52cca2f
Remove more declarations
mhaseeb123 6be4a4b
Add `setup_page_index` to `hybrid_scan_helpers`
mhaseeb123 952baec
Add hybrid scan reader's metadata API implementations
mhaseeb123 133ddd0
Suggestions from code reviews
mhaseeb123 32535d6
style fix
mhaseeb123 7e4474d
Suggestions from code review
mhaseeb123 2111da5
style fix
mhaseeb123 80c9952
Impl rg pruning with stats in expt PQ reader
mhaseeb123 8cbe3c6
Merge branch 'branch-25.06' into fea/filter-row-groups-with-stats
mhaseeb123 10d9cfa
Merge changes
mhaseeb123 736c76c
Improvements
mhaseeb123 9b0cdfc
Minor improvements
mhaseeb123 36973db
Minor improvement
mhaseeb123 c88e8ad
Minor improvements
mhaseeb123 9cf6598
Minor improvements
mhaseeb123 8b4ba9a
fix build error
mhaseeb123 e314dc6
Apply suggestions from reviews
mhaseeb123 eac6235
Use `EXPECT_EQ` instead of `ASSERT_EQ` in tests
mhaseeb123 d7f22da
Merge branch 'branch-25.06' into fea/filter-row-groups-with-stats
mhaseeb123 890c7a8
Merge branch 'branch-25.06' into fea/filter-row-groups-with-stats
mhaseeb123 ca43c1e
Suggestions from code review
mhaseeb123 e837f34
Remove the missed source_info from test
mhaseeb123 8109a61
Minor improvement
mhaseeb123 ff7744d
Minor docs update
mhaseeb123 4f49637
Merge branch 'branch-25.06' into fea/filter-row-groups-with-stats
mhaseeb123 0cb0264
Use hash set to remove filter columns
mhaseeb123 7538030
Revert the file buffer span in test
mhaseeb123 0b82253
Merge branch 'branch-25.06' into fea/filter-row-groups-with-stats
bdice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,17 +29,30 @@ | |
| #include <functional> | ||
| #include <numeric> | ||
| #include <optional> | ||
| #include <unordered_set> | ||
|
|
||
| namespace cudf::io::parquet::experimental::detail { | ||
|
|
||
| using aggregate_reader_metadata_base = parquet::detail::aggregate_reader_metadata; | ||
| using metadata_base = parquet::detail::metadata; | ||
|
|
||
| using io::detail::inline_column_buffer; | ||
| using parquet::detail::CompactProtocolReader; | ||
| using parquet::detail::equality_literals_collector; | ||
| using parquet::detail::input_column_info; | ||
| using parquet::detail::row_group_info; | ||
|
|
||
| namespace { | ||
|
|
||
| [[nodiscard]] auto all_row_group_indices( | ||
| host_span<std::vector<cudf::size_type> const> row_group_indices) | ||
| { | ||
| return std::vector<std::vector<cudf::size_type>>(row_group_indices.begin(), | ||
| row_group_indices.end()); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| metadata::metadata(cudf::host_span<uint8_t const> footer_bytes) | ||
| { | ||
| CompactProtocolReader cp(footer_bytes.data(), footer_bytes.size()); | ||
|
|
@@ -137,4 +150,117 @@ void aggregate_reader_metadata::setup_page_index(cudf::host_span<uint8_t const> | |
| } | ||
| } | ||
|
|
||
| std::tuple<std::vector<input_column_info>, | ||
| std::vector<inline_column_buffer>, | ||
| std::vector<cudf::size_type>> | ||
| aggregate_reader_metadata::select_payload_columns( | ||
vuule marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::optional<std::vector<std::string>> const& payload_column_names, | ||
| std::optional<std::vector<std::string>> const& filter_column_names, | ||
vuule marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| bool include_index, | ||
| bool strings_to_categorical, | ||
| type_id timestamp_type_id) | ||
| { | ||
| // If neither payload nor filter columns are specified, select all columns | ||
| if (not payload_column_names.has_value() and not filter_column_names.has_value()) { | ||
| // Call the base `select_columns()` method without specifying any columns | ||
| return select_columns({}, {}, include_index, strings_to_categorical, timestamp_type_id); | ||
|
Member
Author
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. Base class function selects all columns if the first argument is empty |
||
| } | ||
|
|
||
| std::vector<std::string> valid_payload_columns; | ||
|
|
||
| // If payload columns are specified, only select payload columns that do not appear in the filter | ||
| // expression | ||
| if (payload_column_names.has_value()) { | ||
| valid_payload_columns = *payload_column_names; | ||
| // Remove filter columns from the provided payload column names | ||
| if (filter_column_names.has_value() and not filter_column_names->empty()) { | ||
| // Add filter column names to a hash set for faster lookup | ||
| std::unordered_set<std::string> filter_columns_set(filter_column_names->begin(), | ||
| filter_column_names->end()); | ||
| // Remove a payload column name if it is also present in the hash set | ||
| valid_payload_columns.erase(std::remove_if(valid_payload_columns.begin(), | ||
| valid_payload_columns.end(), | ||
| [&filter_columns_set](auto const& col) { | ||
| return filter_columns_set.count(col) > 0; | ||
| }), | ||
| valid_payload_columns.end()); | ||
| } | ||
| // Call the base `select_columns()` method with valid payload columns | ||
| return select_columns( | ||
| valid_payload_columns, {}, include_index, strings_to_categorical, timestamp_type_id); | ||
| } | ||
|
|
||
| // Else if only filter columns are specified, select all columns that do not appear in the | ||
| // filter expression | ||
|
|
||
| // Add filter column names to a hash set for faster lookup | ||
| std::unordered_set<std::string> filter_columns_set(filter_column_names->begin(), | ||
| filter_column_names->end()); | ||
|
|
||
| std::function<void(std::string, int)> add_column_path = [&](std::string path_till_now, | ||
| int schema_idx) { | ||
| auto const& schema_elem = get_schema(schema_idx); | ||
| std::string const curr_path = path_till_now + schema_elem.name; | ||
| // If the current path is not a filter column, then add it and its children to the list of valid | ||
| // payload columns | ||
| if (filter_columns_set.count(curr_path) == 0) { | ||
| valid_payload_columns.push_back(curr_path); | ||
| // Add all children as well | ||
| for (auto const& child_idx : schema_elem.children_idx) { | ||
| add_column_path(curr_path + ".", child_idx); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Add all but filter columns to valid payload columns | ||
| if (not filter_column_names->empty()) { | ||
| for (auto const& child_idx : get_schema(0).children_idx) { | ||
| add_column_path("", child_idx); | ||
| } | ||
| } | ||
|
|
||
| // Call the base `select_columns()` method with all but filter columns | ||
| return select_columns( | ||
| valid_payload_columns, {}, include_index, strings_to_categorical, timestamp_type_id); | ||
| } | ||
|
|
||
| std::vector<std::vector<cudf::size_type>> aggregate_reader_metadata::filter_row_groups_with_stats( | ||
| host_span<std::vector<cudf::size_type> const> row_group_indices, | ||
| host_span<data_type const> output_dtypes, | ||
| host_span<int const> output_column_schemas, | ||
| std::optional<std::reference_wrapper<ast::expression const>> filter, | ||
| rmm::cuda_stream_view stream) const | ||
| { | ||
| // Return all row groups if no filter expression | ||
| if (not filter.has_value()) { return all_row_group_indices(row_group_indices); } | ||
|
|
||
| // Compute total number of input row groups | ||
| cudf::size_type total_row_groups = [&]() { | ||
| if (not row_group_indices.empty()) { | ||
| size_t const total_row_groups = | ||
| std::accumulate(row_group_indices.begin(), | ||
| row_group_indices.end(), | ||
| size_t{0}, | ||
| [](auto sum, auto const& pfm) { return sum + pfm.size(); }); | ||
|
|
||
| // Check if we have less than 2B total row groups. | ||
| CUDF_EXPECTS(total_row_groups <= std::numeric_limits<cudf::size_type>::max(), | ||
| "Total number of row groups exceed the cudf::size_type's limit"); | ||
| return static_cast<cudf::size_type>(total_row_groups); | ||
| } else { | ||
| return num_row_groups; | ||
| } | ||
| }(); | ||
|
|
||
| // Filter stats table with StatsAST expression and collect filtered row group indices | ||
| auto const stats_filtered_row_group_indices = apply_stats_filters(row_group_indices, | ||
|
Member
Author
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. Reuse the base class utility |
||
| total_row_groups, | ||
| output_dtypes, | ||
| output_column_schemas, | ||
| filter.value(), | ||
| stream); | ||
|
|
||
| return stats_filtered_row_group_indices.value_or(all_row_group_indices(row_group_indices)); | ||
mhaseeb123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } // namespace cudf::io::parquet::experimental::detail | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Will need this in other
filter_row_groups_with_**APIs as well so separated out here.