adriangb commented on code in PR #19446:
URL: https://github.com/apache/datafusion/pull/19446#discussion_r2648260594
##########
datafusion/physical-plan/src/projection.rs:
##########
@@ -357,6 +359,69 @@ impl ExecutionPlan for ProjectionExec {
) -> Result<FilterPushdownPropagation<Arc<dyn ExecutionPlan>>> {
Ok(FilterPushdownPropagation::if_all(child_pushdown_result))
}
+
+ fn try_pushdown_sort(
+ &self,
+ order: &[PhysicalSortExpr],
+ ) -> Result<SortOrderPushdownResult<Arc<dyn ExecutionPlan>>> {
+ let child = self.input();
+ let mut child_order = Vec::new();
+
+ // Check and transform sort expressions
+ for sort_expr in order {
+ // Recursively transform the expression
+ let mut can_pushdown = true;
+ let transformed = Arc::clone(&sort_expr.expr).transform(|expr| {
+ if let Some(col) = expr.as_any().downcast_ref::<Column>() {
+ // Check if column index is valid
Review Comment:
```suggestion
// Check if column index is valid.
// This should always be true but fail gracefully if
it's not.
```
##########
datafusion/physical-plan/src/projection.rs:
##########
@@ -357,6 +359,69 @@ impl ExecutionPlan for ProjectionExec {
) -> Result<FilterPushdownPropagation<Arc<dyn ExecutionPlan>>> {
Ok(FilterPushdownPropagation::if_all(child_pushdown_result))
}
+
+ fn try_pushdown_sort(
+ &self,
+ order: &[PhysicalSortExpr],
+ ) -> Result<SortOrderPushdownResult<Arc<dyn ExecutionPlan>>> {
+ let child = self.input();
+ let mut child_order = Vec::new();
+
+ // Check and transform sort expressions
+ for sort_expr in order {
+ // Recursively transform the expression
+ let mut can_pushdown = true;
+ let transformed = Arc::clone(&sort_expr.expr).transform(|expr| {
+ if let Some(col) = expr.as_any().downcast_ref::<Column>() {
+ // Check if column index is valid
+ if col.index() >= self.expr().len() {
+ can_pushdown = false;
+ return Ok(Transformed::no(expr));
+ }
+
+ let proj_expr = &self.expr()[col.index()];
+
+ // Check if projection expression is a simple column
Review Comment:
```suggestion
// Check if projection expression is a simple column
// We cannot push down order by clauses that depend on
// projected computations as they would have nothing to
reference.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]