alamb commented on code in PR #9906:
URL: https://github.com/apache/arrow-datafusion/pull/9906#discussion_r1548544704
##########
datafusion-examples/examples/advanced_udwf.rs:
##########
@@ -75,6 +78,30 @@ impl WindowUDFImpl for SmoothItUdf {
Ok(DataType::Float64)
}
+ /// rewrite
+ fn simplify(
Review Comment:
This might be confusing as now this example UDWF will never call the actual
implementation.
Perhaps we can make a second UDWF and use it as an example of wrapping an
existing UDWF 🤔
##########
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:
Ah this is interesting. I was trying to figure out how we would update this
signature to avoid a copy (for example, a rewrite would have to copy the
`order_by` exprs 🤔
I can't think of anything at the moment
--
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]