Repository navigation
Add a ScalarUDFImpl::simplfy() API #9289
Description
Activity
FYI @jayzhan211 -- I wonder if you have any thoughts about this ticket (or maybe have time to try implementing it).
I think a good test case would be to implement a udf function such as
cast_to_int64that was rewritten intocast(x as int64)or somethingReacted by Jay Zhancc @universalmind303 and @thinkharderdev as I think you have been thinking about similar things
Reacted by Cory GrinsteadIn this case, should we add a function-level optimizer trying to rewrite the function? I think it would be a large match expression. I have done a similar issue today #9213 . Maybe I could do parts of it.
In this case, should we add a function-level optimizer trying to rewrite the function? I think it would be a large match expression. I have done a similar issue today #9213 . Maybe I could do parts of it.
Yes, @Lordworms I think that is an excellent idea. cc @mustafasrepo for your thoughts
Note that #9213 is for an aggregate function, which I think would have a similar API though it would be on a different struct (
AggreagateUDF)In this case, should we add a function-level optimizer trying to rewrite the function? I think it would be a large match expression. I have done a similar issue today #9213 . Maybe I could do parts of it.
Yes, @Lordworms I think that is an excellent idea. cc @mustafasrepo for your thoughts
Note that #9213 is for an aggregate function, which I think would have a similar API though it would be on a different struct (
AggreagateUDF)I think, function level optimizer would be much more scalable. Also, simplification logic will be more contained. Also, once we can bring similar changes in
ScalarUDFImpl::simplfytoAggregateUDFfor support of this feature.Reacted by Andrew Lamb and Lordworms@jayzhan211 -- I think this proposal is also likely to be needed to get
make_arraymoved into datafusion-functions-array - #9288@alamb How is
simplifylike for array concat operator rewrite? If we have MakeArrayUDF,argsare for MakeArray only, but we need BinaryExpr that includes two array functions and 1 operator to start the simplification. It seems function level optimizer can only works for simplification like A function to B Expr / function.simplify for
arrow_castis just trying to do actual castingx as i64right?@alamb How is
simplifylike for array concat operator rewrite? If we have MakeArrayUDF,argsare for MakeArray only, but we need BinaryExpr that includes two array functions and 1 operator to start the simplification. It seems function level optimizer can only works for simplification like A function to B Expr / function.🤔 that is a good point that the simplification is needed for
StringConcatoperator 🤔simplify for arrow_cast is just trying to do actual casting x as i64 right?
Yes
Sorry for my delay, I have been out the last few days. I am catching up with reviews
Is your feature request related to a problem or challenge?
As part of porting
arrow_cast#9287 andmake_array#9288, it has become clear that some functions have special simplification semantics:arrow_castsimplifies tocastof a particular data type. It is important for the rest of datafusion to understand theCastsemantics as the there are several special cases for Expr::Cast (such asunwrap_cast_in_comparison)make_arrayhas special rewrite rules to combine / fold witharray_appendandarray_prepaendin the simplifier (source link)Also I think some systems may want to provide the ability to define UDFs that are more like macros (can be expressed in terms of other built in expressions), which needs some way for datafusion to "inline" the definition
Similarly, specialized functions (e.g replace
regexp_matchwith a version that had the regexp pre-compiled ...) - #8051 sound very similarDescribe the solution you'd like
I propose adding a function such as the following, we could implement the simplifications for
make_arrayandarrow_castin the UDF (and not in the main simplify code):}
Describe alternatives you've considered
There may be better
Additional context
No response