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

Measure the number of Parquet row groups filtered by predicate pushdown #17594

Conversation

mhaseeb123
Copy link
Member

@mhaseeb123 mhaseeb123 commented Dec 13, 2024

Description

Closes #17164

This PR adds a method to measure the number of remaining row groups after stats and bloom filtering during predicate pushdown.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@mhaseeb123 mhaseeb123 self-assigned this Dec 13, 2024
Copy link

copy-pr-bot bot commented Dec 13, 2024

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions bot added the libcudf Affects libcudf (C++/CUDA) code. label Dec 13, 2024
@mhaseeb123 mhaseeb123 added 2 - In Progress Currently a work in progress DO NOT MERGE Hold off on merging; see PR for details improvement Improvement / enhancement to an existing function labels Dec 13, 2024
@mhaseeb123 mhaseeb123 added cuIO cuIO issue non-breaking Non-breaking change labels Dec 13, 2024
@mhaseeb123 mhaseeb123 removed the DO NOT MERGE Hold off on merging; see PR for details label Jan 15, 2025
@mhaseeb123 mhaseeb123 changed the title 🚧 Add a method to measure the number of Parquet row groups filtered by predicate pushdown Measure the number of Parquet row groups filtered by predicate pushdown Jan 16, 2025
// if filter is not empty, then gather row groups to read after predicate pushdown
if (filter.has_value()) {
filtered_row_group_indices = filter_row_groups(
sources, row_group_indices, output_dtypes, output_column_schemas, filter.value(), stream);
// Span of input row group indices for predicate pushdown
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this piece of code out of filter_row_groups() to make its signature consistent with apply_bloom_filters()

host_span<data_type const> output_dtypes,
host_span<int const> output_column_schemas,
std::reference_wrapper<ast::expression const> filter,
rmm::cuda_stream_view stream) const
{
auto mr = cudf::get_current_device_resource_ref();
// Create row group indices.
Copy link
Member Author

@mhaseeb123 mhaseeb123 Jan 16, 2025

Choose a reason for hiding this comment

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

Moved this piece outside in select_row_groups() to take in input_row_group_indices as input param

std::map<std::string, std::string> user_data; //!< Format-dependent metadata of the first input
//!< file as key-values pairs (deprecated)
std::vector<std::unordered_map<std::string, std::string>>
per_file_user_data; //!< Per file format-dependent metadata as key-values pairs

// The following variables are currently only computed for Parquet reader
size_type num_input_row_groups; //!< Number of input row groups across all data sources
Copy link
Member Author

@mhaseeb123 mhaseeb123 Jan 16, 2025

Choose a reason for hiding this comment

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

Keeping all variables tracking number of row groups as size_type for consistency across the entire Parquet stack. Happy to change it to size_t all across in a separate PR if needed. @vuule @nvdbaranec

@mhaseeb123 mhaseeb123 marked this pull request as ready for review January 16, 2025 04:08
@mhaseeb123 mhaseeb123 requested a review from a team as a code owner January 16, 2025 04:08
@mhaseeb123 mhaseeb123 requested review from bdice, ttnghia and vuule January 16, 2025 04:08
bloom_filter_spans, parquet_types, total_row_groups, equality_col_schemas.size()};
bloom_filter_caster const bloom_filter_col{bloom_filter_spans,
parquet_types,
static_cast<size_t>(total_row_groups),
Copy link
Member Author

Choose a reason for hiding this comment

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

static_cast simply reformatted this line


// The following variables are currently only computed for Parquet reader
size_type num_input_row_groups{0}; //!< Total number of input row groups across all data sources
std::optional<size_type>
Copy link
Member Author

@mhaseeb123 mhaseeb123 Jan 28, 2025

Choose a reason for hiding this comment

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

Edit: With recent updates to this PR:

  • num_row_groups_after_stats_filter will be std::nullopt if not filter.has_value() and equal to num_input_row_groups or actual value otherwise
  • num_row_groups_after_bloom_filter will be std::nullopt if not filter.has_value() or not bloom_filter_exist and equal to num_row_groups_after_stats_filter or actual value otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

^ Updated

// pushdown.
out_metadata.num_input_row_groups = _file_itm_data.num_input_row_groups;
// Copy the number surviving row groups from each predicate pushdown only if the filter has value.
if (_expr_conv.get_converted_expr().has_value()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy from _file_itm_data if filter.has_value()

@@ -451,29 +428,55 @@ std::optional<std::vector<std::vector<size_type>>> aggregate_reader_metadata::fi
// Converts AST to StatsAST with reference to min, max columns in above `stats_table`.
stats_expression_converter const stats_expr{filter.get(),
static_cast<size_type>(output_dtypes.size())};
auto stats_ast = stats_expr.get_stats_expr();
Copy link
Member Author

@mhaseeb123 mhaseeb123 Jan 28, 2025

Choose a reason for hiding this comment

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

Removed this stale code (already moved inside collect_filtered_row_group_indices)


// Filter stats table with StatsAST expression and collect filtered row group indices
auto const filtered_row_group_indices = collect_filtered_row_group_indices(
stats_table, stats_expr.get_stats_expr(), input_row_group_indices, stream);

// Number of surviving row groups after applying stats filter
auto const num_stats_filtered_row_groups =
Copy link
Member Author

Choose a reason for hiding this comment

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

There isn't really a straightforward way in here to check if stats weren't available so this will be set to either total_row_groups or the filtered number of row groups.

Copy link
Contributor

Choose a reason for hiding this comment

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

so if there is a filter, but no stats, we still report a num_stats_filtered_row_groups number, even though we didn't really do any stats-based filtering?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah unfortunately, not that straightforward to check the availability of stats right now!

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #17864 to handle this in future PR

cpp/include/cudf/io/types.hpp Outdated Show resolved Hide resolved

// Filter stats table with StatsAST expression and collect filtered row group indices
auto const filtered_row_group_indices = collect_filtered_row_group_indices(
stats_table, stats_expr.get_stats_expr(), input_row_group_indices, stream);

// Number of surviving row groups after applying stats filter
auto const num_stats_filtered_row_groups =
Copy link
Contributor

Choose a reason for hiding this comment

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

so if there is a filter, but no stats, we still report a num_stats_filtered_row_groups number, even though we didn't really do any stats-based filtering?

Copy link
Contributor

@vuule vuule left a comment

Choose a reason for hiding this comment

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

Approving; my remaining comments are non-blocking

@mhaseeb123 mhaseeb123 added feature request New feature or request and removed improvement Improvement / enhancement to an existing function labels Jan 30, 2025
@mhaseeb123 mhaseeb123 requested a review from mythrocks January 30, 2025 19:20
Copy link
Contributor

@mythrocks mythrocks left a comment

Choose a reason for hiding this comment

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

I'm 👍. A couple of nitpicks are mentioned, but needn't hold up this change.

@mhaseeb123
Copy link
Member Author

/merge

@mhaseeb123 mhaseeb123 added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 4 - Needs Review Waiting for reviewer to review or respond labels Jan 30, 2025
@rapids-bot rapids-bot bot merged commit 10c1fb4 into rapidsai:branch-25.02 Jan 31, 2025
109 checks passed
@mhaseeb123 mhaseeb123 deleted the fea/measure-predicate-pushdown-row-groups branch January 31, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge cuIO cuIO issue feature request New feature or request libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change
Projects
Status: Landed
Development

Successfully merging this pull request may close these issues.

[FEA] Use bloom filters in Parquet reader to filter row groups with equality predicates
4 participants