jayshrivastava commented on PR #22011:
URL: https://github.com/apache/datafusion/pull/22011#issuecomment-4374173148

   We may alternatively use `map_expressions` (unmerged, see 
https://github.com/apache/datafusion/issues/20899) to set dynamic filters or 
`apply_expressions` (merged, see 
https://github.com/apache/datafusion/pull/20337) to get dynamic filters.
   
   I'll leave it up to reviewers for thoughts on this. This is the 
`apply_expressions` implementation for `AggregateExec`.
   ```
   fn apply_expressions(
           &self,
           f: &mut dyn FnMut(&dyn PhysicalExpr) -> Result<TreeNodeRecursion>,
       ) -> Result<TreeNodeRecursion> {
           // Apply to group by expressions
           let mut tnr = TreeNodeRecursion::Continue;
           for expr in self.group_by.input_exprs() {
               tnr = tnr.visit_sibling(|| f(expr.as_ref()))?;
           }
   
           // Apply to aggregate expressions
           for aggr in self.aggr_expr.iter() {
               for expr in aggr.expressions() {
                   tnr = tnr.visit_sibling(|| f(expr.as_ref()))?;
               }
           }
   
           // Apply to filter expressions (FILTER WHERE clauses)
           for filter in self.filter_expr.iter().flatten() {
               tnr = tnr.visit_sibling(|| f(filter.as_ref()))?;
           }
   
           // Apply to dynamic filter expression if present
           if let Some(dyn_filter) = &self.dynamic_filter {
               tnr = tnr.visit_sibling(|| f(dyn_filter.filter.as_ref()))?;
           }
   
           Ok(tnr)
       }
   ```
   We currently expose all these expressions via public methods 
   ```
     /// Grouping expressions
       pub fn group_expr(&self) -> &PhysicalGroupBy {
           &self.group_by
       }
   
       /// Grouping expressions as they occur in the output schema
       pub fn output_group_expr(&self) -> Vec<Arc<dyn PhysicalExpr>> {
           self.group_by.output_exprs()
       }
   
       /// Aggregate expressions
       pub fn aggr_expr(&self) -> &[Arc<AggregateFunctionExpr>] {
           &self.aggr_expr
       }
   
       /// FILTER (WHERE clause) expression for each aggregate expression
       pub fn filter_expr(&self) -> &[Option<Arc<dyn PhysicalExpr>>] {
           &self.filter_expr
       }
   ```
   So, I added `pub fn dynamic_filter()`.


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