refactor: Optimize required_columns from BTreeSet to Vec in struct PushdownChecker#19678
Conversation
|
cc @kosiew |
9e5d7ba to
8c2462e
Compare
kosiew
left a comment
There was a problem hiding this comment.
Thanks @kumarUjjawal for contributing.
I left some comments for your consideration.
| if !self.required_columns.contains(&idx) { | ||
| self.required_columns.push(idx); | ||
| } |
There was a problem hiding this comment.
I think it would help future contributors to
- Add comment explaining linear search is acceptable for small
n- OR switch to
HashSetfor O(1) deduplication ifnmight grow
- OR switch to
| let prevents_pushdown = checker.prevents_pushdown(); | ||
| let nested = checker.nested_behavior; | ||
| let mut required_columns = checker.required_columns; | ||
| required_columns.sort_unstable(); |
There was a problem hiding this comment.
how about adding:
impl PushdownChecker {
fn into_sorted_columns(mut self) -> PushdownColumns {
self.required_columns.sort_unstable();
self.required_columns.dedup(); // this removes the need for contains check
PushdownColumns {
required_columns: self.required_columns,
nested: self.nested_behavior,
}
}| Ok((!prevents_pushdown).then_some(PushdownColumns { | ||
| required_columns, | ||
| nested, | ||
| })) |
There was a problem hiding this comment.
and then rewriting this to:
Ok((!checker.prevents_pushdown())
.then_some(checker.into_sorted_columns()))| if !self.required_columns.contains(&idx) { | ||
| self.required_columns.push(idx); | ||
| } |
There was a problem hiding this comment.
see suggested
fn into_sorted_columns
below
Thanks for the feedback. Incorporated the changes. |
alamb
left a comment
There was a problem hiding this comment.
Thanks @kumarUjjawal and @kosiew -- this is really nice
| projected_columns: bool, | ||
| /// Indices into the file schema of columns required to evaluate the expression. | ||
| required_columns: BTreeSet<usize>, | ||
| required_columns: Vec<usize>, |
| #[derive(Debug)] | ||
| struct PushdownColumns { | ||
| required_columns: BTreeSet<usize>, | ||
| required_columns: Vec<usize>, |
There was a problem hiding this comment.
maybe it is worth a comment here explaining the assumption that required_columns are sorted and unique (non duplicate)
…uct `PushdownChecker` (apache#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 apache#123` indicates that this PR will close issue apache#123. --> - Closes apache#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. -->
Which issue does this PR close?
required_columnsfromBTreeSet<usize>toVec<usize>in struct PushdownChecker<'schema> #19673.Rationale for this change
What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?