2010YOUY01 commented on code in PR #20712:
URL: https://github.com/apache/datafusion/pull/20712#discussion_r2887067969
##########
datafusion/expr/src/udaf.rs:
##########
@@ -651,26 +651,29 @@ pub trait AggregateUDFImpl: Debug + DynEq + DynHash +
Send + Sync {
AggregateOrderSensitivity::HardRequirement
}
- /// Optionally apply per-UDaF simplification / rewrite rules.
+ /// Returns an optional hook for simplifying this user-defined aggregate.
///
- /// This can be used to apply function specific simplification rules during
- /// optimization (e.g. `arrow_cast` --> `Expr::Cast`). The default
- /// implementation does nothing.
+ /// Use this hook to apply function-specific rewrites during optimization.
+ /// The default implementation returns `None`.
///
- /// 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.
+ /// For example, `percentile_cont(x, 0.0)` and `percentile_cont(x, 1.0)`
can
+ /// be rewritten to `MIN(x)` or `MAX(x)` depending on the `ORDER BY`
+ /// direction.
+ ///
+ /// DataFusion already simplifies arguments and performs constant folding
+ /// (for example, `my_add(1, 2) -> 3`), so there is usually no need to
+ /// implement those optimizations manually for specific UDFs.
Review Comment:
```suggestion
/// DataFusion already simplifies arguments and performs constant folding
/// (for example, `my_add(1, 2) -> 3`). For nested expressions, the
optimizer
/// runs simplification in multiple passes, so arguments are typically
/// simplified before this hook is invoked. As a result, UDF
implementations
/// usually do not need to handle argument simplification themselves.
///
/// See configuration `datafusion.optimizer.max_passes` for details on
how many
/// optimization passes may be applied.
```
Added some details about how constant folding is applied before udf
simplification
--
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]