Uh oh!
There was an error while loading. Please reload this page.
feature: Add a WindowUDFImpl::simplify() API - #9906
Conversation
guojidan
commented
Apr 2, 2024
hi @jayzhan211 , maybe you can review this PR 😄 |
@guojidan I think we need a simple example. Something like simplifying |
guojidan
commented
Apr 2, 2024
separate create a new UDWF example file? |
We have example of You need to write an example in |
alamb
commented
Apr 2, 2024
I agree with @jayzhan211 that an example would be great ❤️ |
| } | ||
| /// rewrite | ||
| fn simplify( |
There was a problem hiding this 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 🤔
| fn simplify( | ||
| &self, | ||
| args: Vec<Expr>, | ||
| _partition_by: &[Expr], |
There was a problem hiding this 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
There was a problem hiding this comment.
it looks quite hard to come up with better backward compatible solution
There was a problem hiding this comment.
It would be great if we would not need do to decompose and then compose function again, something like:
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
| args: Vec<Expr>, | ||
| _partition_by: &[Expr], | ||
| _order_by: &[Expr], | ||
| _window_frame: &WindowFrame, |
There was a problem hiding this comment.
Thats probably better to use builder pattern, if the mandatory and optional input params are different
There was a problem hiding this comment.
I don't quite understand what to do. Can you further explain 😄
alamb
commented
Apr 4, 2024
Marking as draft as I think this PR is no longer waiting on feedback. Please mark it as ready for review when it is ready for another look |
Signed-off-by: guojidan <1948535941@qq.com>
milenkovicm
commented
May 17, 2024
I guess at some point we'd need to change |
| /// this function will simplify `SimplifySmoothItUdf` to `SmoothItUdf`. | ||
| fn simplify(&self) -> Option<WindowFunctionSimplification> { | ||
| // Ok(ExprSimplifyResult::Simplified(Expr::WindowFunction( |
alamb
left a comment
There was a problem hiding this comment.
Thanks @guojidan and @jayzhan211 for the review
I think there are some cleanups (liek https://github.com/apache/datafusion/pull/9906/files#r1618798950 from @jayzhan211 ) that we should do but we can do them as follow on PRs too.
Thank you
* feature: Add a WindowUDFImpl::simplfy() API Signed-off-by: guojidan <1948535941@qq.com> * fix doc Signed-off-by: guojidan <1948535941@qq.com> * fix fmt Signed-off-by: guojidan <1948535941@qq.com> --------- Signed-off-by: guojidan <1948535941@qq.com>
Which issue does this PR close?
Closes#9527 .
Rationale for this change
allow user define simply rule
What changes are included in this PR?
add
WindowUDFImpl::simplfy()APIAre these changes tested?
Are there any user-facing changes?