apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.29k stars 973 forks source link

Introduce expr builder for aggregate function #10560

Open jayzhan211 opened 2 weeks ago

jayzhan211 commented 2 weeks ago

Which issue does this PR close?

Closes #10545.

Rationale for this change

After this PR, there are two kinds of expression API. One is the normal one like count(expr), convenient for expression that has few arguments. Another is builder mode, useful for expressions that expects multiple kind of arguments, like first_value_builder(expr).order_by().build()

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

jayzhan211 commented 2 weeks ago

I plan to add distinct macro in the follow up PR for count.

alamb commented 2 weeks ago

This looks super cool @jayzhan211

alamb commented 1 week ago

THanks @jayzhan211 -- I will plan to review this tomorrow.

jayzhan211 commented 1 week ago

which means both adding many new functions as well as that they won't work for user defined aggregate functions

I think they can build the function with macro in function-aggregate, so they can have their function with ExprBuilder extension. But then I need to move the macro to datafusion-expr 🤔

maybe make an extension trait

It could be a good idea

jayzhan211 commented 1 week ago

Maybe we can just extend function for AggregateFunction 🤔

pub fn call(&self, args: Vec<Expr>) -> AggregateFunction

impl AggregateFunction {
  fn build() -> Expr
}