timsaucer opened a new pull request, #11550: URL: https://github.com/apache/datafusion/pull/11550
## Which issue does this PR close? Closes #6747. ## Rationale for this change There was excellent work done on https://github.com/apache/datafusion/pull/10560 that makes a much more easy to use interface for developers to set parameters on aggregate functions. This PR is designed to bring the same interface to window functions. Currently it can be very clunky to write a window function for a relatively simple query. For example to create a lag function you would do: ``` let lag_expr = Expr::WindowFunction(WindowFunction::new( WindowFunctionDefinition::BuiltInWindowFunction( BuiltInWindowFunction::Lag, ), vec![col("array_col")], vec![], vec![], WindowFrame::new(None), None, )); ``` With this PR it becomes a simpler ``` let lag_expr = lag(col("array_col")); ``` Even more powerful is that you can now convert window function expressions into their builder to set additional properties ``` let lag_expr = lag(col("array_col")).null_treatment(NullTreatment::IgnoreNulls).build()?; ``` ## What changes are included in this PR? This PR refactors `AggregateExt` to be `ExprFunctionExt` and adds in additional functions for `partition_by` and `window_frame`. It also adds in a variety of useful helper functions for things like `lead`, `lag`, `row_number` etc. ## Are these changes tested? All existing CI tests pass. Some were updated to use the new interface, but all of the functionality remains the same. ## Are there any user-facing changes? `WindowFunction::new` now only requires two parameters, the function definition and arguments. Other parameters will need to be set using the builder methods provided. For example, if the user was previously calling ``` let max1 = Expr::WindowFunction(expr::WindowFunction::new( WindowFunctionDefinition::AggregateFunction(AggregateFunction::Max), vec![col("name")], vec![], vec![age_asc.clone(), name_desc.clone()], WindowFrame::new(Some(false)), None, )); ``` They would change this to ``` let max1 = Expr::WindowFunction(expr::WindowFunction::new( WindowFunctionDefinition::AggregateFunction(AggregateFunction::Max), vec![col("name")])) .order_by(vec![age_asc.clone(), name_desc.clone()]) .build() .unwrap(); ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org