This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 429f5a792f refactor: Optimize `required_columns` from `BTreeSet` to
`Vec` in struct `PushdownChecker` (#19678)
429f5a792f is described below
commit 429f5a792f11dde440f58f7796ec03b05722b74a
Author: Kumar Ujjawal <[email protected]>
AuthorDate: Wed Jan 14 10:16:42 2026 +0530
refactor: Optimize `required_columns` from `BTreeSet` to `Vec` in struct
`PushdownChecker` (#19678)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #19673.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
## What changes are included in this PR?
- Changed
[row_filter.rs](https://github.com/apache/datafusion/blob/main/datafusion/datasource-parquet/src/row_filter.rs)
to use Vec instead of the BTreeSet
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
## Are these changes tested?
Yes
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
---
datafusion/datasource-parquet/src/row_filter.rs | 33 +++++++++++++++++++------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/datafusion/datasource-parquet/src/row_filter.rs
b/datafusion/datasource-parquet/src/row_filter.rs
index 04c11b8875..bc195f1767 100644
--- a/datafusion/datasource-parquet/src/row_filter.rs
+++ b/datafusion/datasource-parquet/src/row_filter.rs
@@ -276,7 +276,7 @@ struct PushdownChecker<'schema> {
/// Does the expression reference any columns not present in the file
schema?
projected_columns: bool,
/// Indices into the file schema of columns required to evaluate the
expression.
- required_columns: BTreeSet<usize>,
+ required_columns: Vec<usize>,
/// Tracks the nested column behavior found during traversal.
nested_behavior: NestedColumnSupport,
/// Whether nested list columns are supported by the predicate semantics.
@@ -290,7 +290,7 @@ impl<'schema> PushdownChecker<'schema> {
Self {
non_primitive_columns: false,
projected_columns: false,
- required_columns: BTreeSet::default(),
+ required_columns: Vec::new(),
nested_behavior: NestedColumnSupport::PrimitiveOnly,
allow_list_columns,
file_schema,
@@ -307,7 +307,8 @@ impl<'schema> PushdownChecker<'schema> {
}
};
- self.required_columns.insert(idx);
+ // Duplicates are handled by dedup() in into_sorted_columns()
+ self.required_columns.push(idx);
let data_type = self.file_schema.field(idx).data_type();
if DataType::is_nested(data_type) {
@@ -355,6 +356,21 @@ impl<'schema> PushdownChecker<'schema> {
fn prevents_pushdown(&self) -> bool {
self.non_primitive_columns || self.projected_columns
}
+
+ /// Consumes the checker and returns sorted, deduplicated column indices
+ /// wrapped in a `PushdownColumns` struct.
+ ///
+ /// This method sorts the column indices and removes duplicates. The sort
+ /// is required because downstream code relies on column indices being in
+ /// ascending order for correct schema projection.
+ fn into_sorted_columns(mut self) -> PushdownColumns {
+ self.required_columns.sort_unstable();
+ self.required_columns.dedup();
+ PushdownColumns {
+ required_columns: self.required_columns,
+ nested: self.nested_behavior,
+ }
+ }
}
impl TreeNodeVisitor<'_> for PushdownChecker<'_> {
@@ -390,9 +406,13 @@ enum NestedColumnSupport {
Unsupported,
}
+/// Result of checking which columns are required for filter pushdown.
#[derive(Debug)]
struct PushdownColumns {
- required_columns: BTreeSet<usize>,
+ /// Sorted, unique column indices into the file schema required to evaluate
+ /// the filter expression. Must be in ascending order for correct schema
+ /// projection matching.
+ required_columns: Vec<usize>,
nested: NestedColumnSupport,
}
@@ -411,10 +431,7 @@ fn pushdown_columns(
let allow_list_columns = supports_list_predicates(expr);
let mut checker = PushdownChecker::new(file_schema, allow_list_columns);
expr.visit(&mut checker)?;
- Ok((!checker.prevents_pushdown()).then_some(PushdownColumns {
- required_columns: checker.required_columns,
- nested: checker.nested_behavior,
- }))
+ Ok((!checker.prevents_pushdown()).then(|| checker.into_sorted_columns()))
}
fn leaf_indices_for_roots(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]