milenkovicm commented on code in PR #9906:
URL: https://github.com/apache/datafusion/pull/9906#discussion_r1587483960
##########
datafusion/expr/src/udwf.rs:
##########
@@ -266,6 +290,35 @@ pub trait WindowUDFImpl: Debug + Send + Sync {
fn aliases(&self) -> &[String] {
&[]
}
+
+ /// Optionally apply per-UDWF simplification / rewrite rules.
+ ///
+ /// This can be used to apply function specific simplification rules during
+ /// optimization. The default implementation does nothing.
+ ///
+ /// Note that DataFusion handles simplifying arguments and "constant
+ /// folding" (replacing a function call with constant arguments such as
+ /// `my_add(1,2) --> 3` ). Thus, there is no need to implement such
+ /// optimizations manually for specific UDFs.
+ ///
+ /// Example:
+ /// [`advanced_udwf.rs`]:
<https://github.com/apache/arrow-datafusion/blob/main/datafusion-examples/examples/advanced_udwf.rs>
+ ///
+ /// # Returns
+ /// [`ExprSimplifyResult`] indicating the result of the simplification NOTE
+ /// if the function cannot be simplified, the arguments *MUST* be returned
+ /// unmodified
+ fn simplify(
+ &self,
+ args: Vec<Expr>,
+ _partition_by: &[Expr],
Review Comment:
It would be great if we would not need do to decompose and then compose
function again, something like:
```rust
Expr::AggregateFunction(AggregateFunction {
func_def:AggregateFunctionDefinition::UDF(ref udaf),
ref args,
ref distinct,
ref filter,
ref order_by,
ref null_treatment }) => {
match udaf.simplify(args, distinct, &filter, &order_by,
&null_treatment)? {
ExprSimplifyResult::Simplified(simplified) =>
Transformed::yes(simplified),
ExprSimplifyResult::Original(_) => Transformed::no(expr),
}
}
```
clone of args could be avoided if simplify returns empty vector ... but that
breaks semantics of the api
--
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]