-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Refactor DataSourceExec::try_swapping_with_projection to simplify and remove abstraction leakage #17395
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
Refactor DataSourceExec::try_swapping_with_projection to simplify and remove abstraction leakage #17395
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62632bf
refactor DataSourceExec::try_swapping_with_projection to simplify and…
adriangb d6a6129
fix docs
adriangb d3df13b
fix docs
adriangb 34338cd
fix docs
adriangb 2be1eb2
fix docs
adriangb de3f3a3
remove ProjectionExec
adriangb 73e0aaa
just return
adriangb c979700
Add to upgrade guide
adriangb 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
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 |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ use log::trace; | |
| #[derive(Debug, Clone)] | ||
| pub struct ProjectionExec { | ||
| /// The projection expressions stored as tuples of (expression, output column name) | ||
| pub(crate) expr: Vec<(Arc<dyn PhysicalExpr>, String)>, | ||
| pub(crate) expr: Vec<ProjectionExpr>, | ||
| /// The schema once the projection has been applied to the input | ||
| schema: SchemaRef, | ||
| /// The input plan | ||
|
|
@@ -75,7 +75,7 @@ pub struct ProjectionExec { | |
| impl ProjectionExec { | ||
| /// Create a projection on an input | ||
| pub fn try_new( | ||
| expr: Vec<(Arc<dyn PhysicalExpr>, String)>, | ||
| expr: Vec<ProjectionExpr>, | ||
| input: Arc<dyn ExecutionPlan>, | ||
| ) -> Result<Self> { | ||
| let input_schema = input.schema(); | ||
|
|
@@ -115,7 +115,7 @@ impl ProjectionExec { | |
| } | ||
|
|
||
| /// The projection expressions stored as tuples of (expression, output column name) | ||
| pub fn expr(&self) -> &[(Arc<dyn PhysicalExpr>, String)] { | ||
| pub fn expr(&self) -> &[ProjectionExpr] { | ||
| &self.expr | ||
| } | ||
|
|
||
|
|
@@ -147,6 +147,8 @@ impl ProjectionExec { | |
| } | ||
| } | ||
|
|
||
| pub type ProjectionExpr = (Arc<dyn PhysicalExpr>, String); | ||
|
Contributor
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. I recommend a future PR transform this into a struct with named fields. That will be a breaking change so I am not going to do it in this PR, it should be done in isolation. |
||
|
|
||
| impl DisplayAs for ProjectionExec { | ||
| fn fmt_as( | ||
| &self, | ||
|
|
@@ -566,7 +568,7 @@ fn is_projection_removable(projection: &ProjectionExec) -> bool { | |
|
|
||
| /// Given the expression set of a projection, checks if the projection causes | ||
| /// any renaming or constructs a non-`Column` physical expression. | ||
| pub fn all_alias_free_columns(exprs: &[(Arc<dyn PhysicalExpr>, String)]) -> bool { | ||
| pub fn all_alias_free_columns(exprs: &[ProjectionExpr]) -> bool { | ||
| exprs.iter().all(|(expr, alias)| { | ||
| expr.as_any() | ||
| .downcast_ref::<Column>() | ||
|
|
@@ -579,11 +581,10 @@ pub fn all_alias_free_columns(exprs: &[(Arc<dyn PhysicalExpr>, String)]) -> bool | |
| /// projection operator's expressions. To use this function safely, one must | ||
| /// ensure that all expressions are `Column` expressions without aliases. | ||
| pub fn new_projections_for_columns( | ||
| projection: &ProjectionExec, | ||
| projection: &[ProjectionExpr], | ||
| source: &[usize], | ||
| ) -> Vec<usize> { | ||
| projection | ||
| .expr() | ||
| .iter() | ||
| .filter_map(|(expr, _)| { | ||
| expr.as_any() | ||
|
|
@@ -604,7 +605,7 @@ pub fn make_with_child( | |
| } | ||
|
|
||
| /// Returns `true` if all the expressions in the argument are `Column`s. | ||
| pub fn all_columns(exprs: &[(Arc<dyn PhysicalExpr>, String)]) -> bool { | ||
| pub fn all_columns(exprs: &[ProjectionExpr]) -> bool { | ||
| exprs.iter().all(|(expr, _)| expr.as_any().is::<Column>()) | ||
| } | ||
|
|
||
|
|
@@ -627,7 +628,7 @@ pub fn all_columns(exprs: &[(Arc<dyn PhysicalExpr>, String)]) -> bool { | |
| /// `a@0`, but `b@2` results in `None` since the projection does not include `b`. | ||
| pub fn update_expr( | ||
| expr: &Arc<dyn PhysicalExpr>, | ||
| projected_exprs: &[(Arc<dyn PhysicalExpr>, String)], | ||
| projected_exprs: &[ProjectionExpr], | ||
| sync_with_child: bool, | ||
| ) -> Result<Option<Arc<dyn PhysicalExpr>>> { | ||
| #[derive(Debug, PartialEq)] | ||
|
|
@@ -692,7 +693,7 @@ pub fn update_expr( | |
| /// expressions using the [`update_expr`] function. | ||
| pub fn update_ordering( | ||
| ordering: LexOrdering, | ||
| projected_exprs: &[(Arc<dyn PhysicalExpr>, String)], | ||
| projected_exprs: &[ProjectionExpr], | ||
| ) -> Result<Option<LexOrdering>> { | ||
| let mut updated_exprs = vec![]; | ||
| for mut sort_expr in ordering.into_iter() { | ||
|
|
@@ -710,7 +711,7 @@ pub fn update_ordering( | |
| /// expressions using the [`update_expr`] function. | ||
| pub fn update_ordering_requirement( | ||
| reqs: LexRequirement, | ||
| projected_exprs: &[(Arc<dyn PhysicalExpr>, String)], | ||
| projected_exprs: &[ProjectionExpr], | ||
| ) -> Result<Option<LexRequirement>> { | ||
| let mut updated_exprs = vec![]; | ||
| for mut sort_expr in reqs.into_iter() { | ||
|
|
@@ -727,7 +728,7 @@ pub fn update_ordering_requirement( | |
| /// Downcasts all the expressions in `exprs` to `Column`s. If any of the given | ||
| /// expressions is not a `Column`, returns `None`. | ||
| pub fn physical_to_column_exprs( | ||
| exprs: &[(Arc<dyn PhysicalExpr>, String)], | ||
| exprs: &[ProjectionExpr], | ||
| ) -> Option<Vec<(Column, String)>> { | ||
| exprs | ||
| .iter() | ||
|
|
@@ -952,7 +953,7 @@ fn try_unifying_projections( | |
| } | ||
|
|
||
| /// Collect all column indices from the given projection expressions. | ||
| fn collect_column_indices(exprs: &[(Arc<dyn PhysicalExpr>, String)]) -> Vec<usize> { | ||
| fn collect_column_indices(exprs: &[ProjectionExpr]) -> Vec<usize> { | ||
| // Collect indices and remove duplicates. | ||
| let mut indices = exprs | ||
| .iter() | ||
|
|
@@ -1314,7 +1315,7 @@ mod tests { | |
| // of output schema columns < input schema columns and hence if we use the last few columns | ||
| // from the input schema in the expressions here, bounds_check would fail on them if output | ||
| // schema is supplied to the partitions_statistics method. | ||
| let exprs: Vec<(Arc<dyn PhysicalExpr>, String)> = vec![ | ||
| let exprs: Vec<ProjectionExpr> = vec![ | ||
| ( | ||
| Arc::new(Column::new("c", 2)) as Arc<dyn PhysicalExpr>, | ||
| "c_renamed".to_string(), | ||
|
|
||
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
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.
We get to remove all of this complexity now 😄
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.
for anyone wondering why: previously we had to store cache information because it was lost on projection (#17077).
Now
FileScanConfig::eq_propertiesworks correctly (fixed by Adrian in #17323), so when passed toDataSourceExec, the new information is used