Is your feature request related to a problem or challenge?
If we move the built-in function out of the optimizer, it is more easy to extend/adapt the optimizer rule to other UDAFs. For example, change the first_value (datafusion builtin) to first_value (UDAF) or my_function (UDAF) in replace_distinct_aggregate.
Discussion from #10648 (comment)
Describe the solution you'd like
- Move the
replace_distinct_aggregate to functions-aggregate as part of the builtin optimize rule, and register the rule to optimizer rules
- Enable FunctionRegistry in the optimizer rule, we always get the function with the name
"first_value" here, if they have first_value UDAF, they can take advantage of this rule by replacing the first_value to their version.
Describe alternatives you've considered
No response
Additional context
No response