adriangb commented on code in PR #19619:
URL: https://github.com/apache/datafusion/pull/19619#discussion_r2672560276


##########
datafusion/physical-plan/src/filter.rs:
##########
@@ -619,7 +686,23 @@ impl ExecutionPlan for FilterExec {
 
 impl EmbeddedProjection for FilterExec {
     fn with_projection(&self, projection: Option<Vec<usize>>) -> Result<Self> {
-        self.with_projection(projection)
+        // Check if the projection is valid
+        can_project(&self.schema(), projection.as_ref())?;
+
+        let projection = match projection {
+            Some(projection) => match &self.projection {
+                Some(p) => Some(projection.iter().map(|i| p[*i]).collect()),
+                None => Some(projection),
+            },
+            None => None,
+        };
+
+        FilterExecBuilder::new(Arc::clone(&self.predicate), 
Arc::clone(&self.input))
+            .with_projection(projection)
+            .with_default_selectivity(self.default_selectivity)
+            .with_batch_size(self.batch_size)
+            .with_fetch(self.fetch)
+            .build()

Review Comment:
   I still don't get it. The old `with_projection` also built a new 
`FilterExec`:
   
   ```rust
   let cache = Self::compute_properties(
       &self.input,
       &self.predicate,
       self.default_selectivity,
       projection.as_ref(),
   )?;
   Ok(Self {
       predicate: Arc::clone(&self.predicate),
       input: Arc::clone(&self.input),
       metrics: self.metrics.clone(),
       default_selectivity: self.default_selectivity,
       cache,
       projection,
       batch_size: self.batch_size,
       fetch: self.fetch,
   })
   ```
   
   The only difference I see is that the old implementation composed 
projections, the new one replaces them. So maybe all we need to do is implement 
the projection composition in `FilterExecBuilder::with_projection` to match the 
existing behavior?



-- 
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]

Reply via email to