jayzhan211 commented on code in PR #10214:
URL: https://github.com/apache/datafusion/pull/10214#discussion_r1579366076
##########
datafusion/expr/src/udaf.rs:
##########
@@ -354,6 +360,24 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
fn aliases(&self) -> &[String] {
&[]
}
+
+ /// Construct an expression that calculates the aggregate in reverse.
+ /// Typically the "reverse" expression is itself (e.g. SUM, COUNT).
+ /// For aggregates that do not support calculation in reverse,
+ /// returns None (which is the default value).
+ fn reverse_expr(&self) -> ReversedExpr {
+ ReversedExpr::NotSupported
+ }
+}
+
+#[derive(Debug)]
+pub enum ReversedExpr {
+ /// The expression is the same as the original expression, like SUM, COUNT
+ Identical,
+ /// The expression does not support reverse calculation, like ArrayAgg
+ NotSupported,
+ /// The expression is different from the original expression
+ Reversed(AggregateFunction),
Review Comment:
You can see the reverse expr in OrderSensitiveArrayAgg
```rust
fn reverse_expr(&self) -> Option<Arc<dyn AggregateExpr>> {
Some(Arc::new(Self {
name: self.name.to_string(),
input_data_type: self.input_data_type.clone(),
expr: self.expr.clone(),
nullable: self.nullable,
order_by_data_types: self.order_by_data_types.clone(),
// Reverse requirement:
ordering_req: reverse_order_bys(&self.ordering_req),
reverse: !self.reverse,
}))
}
```
We need the ordering info, it is not contained in either `AggregateUDF` or
`AggregateUDFImpl` function. Therefore, I return `AggregateFunction` instead.
Then, we can create AggregateExec with `create_physical_expr` to get the
physical-expr from these logical exprs.
--
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]