-
Notifications
You must be signed in to change notification settings - Fork 1.9k
refactor: Optimize required_columns from BTreeSet to Vec in struct PushdownChecker
#19678
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)] | ||
alamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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>, | ||
|
Contributor
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. maybe it is worth a comment here explaining the assumption that |
||
| 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( | ||
|
|
||
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.
❤️