mustafasrepo commented on code in PR #6482: URL: https://github.com/apache/arrow-datafusion/pull/6482#discussion_r1212744166
########## datafusion/core/src/physical_plan/aggregates/mod.rs: ########## @@ -339,40 +340,96 @@ fn output_group_expr_helper(group_by: &PhysicalGroupBy) -> Vec<Arc<dyn PhysicalE .collect() } +/// This function returns the ordering requirement of the first non-reversible +/// order-sensitive aggregate function such as ARRAY_AGG. This requirement serves +/// as the initial requirement while calculating the finest requirement among all +/// aggregate functions. If this function returns `None`, it means there is no +/// hard ordering requirement for the aggregate functions (in terms of direction). +/// Then, we can generate two alternative requirements with opposite directions. +fn get_init_req( + aggr_expr: &[Arc<dyn AggregateExpr>], + order_by_expr: &[Option<LexOrdering>], +) -> Option<LexOrdering> { + for (aggr_expr, fn_reqs) in aggr_expr.iter().zip(order_by_expr.iter()) { + // If the aggregation function is a non-reversible order-sensitive function + // and there is a hard requirement, choose first such requirement: + if is_order_sensitive(aggr_expr) + && aggr_expr.reverse_expr().is_none() + && fn_reqs.is_some() + { + return fn_reqs.clone(); + } + } + None +} + +fn get_finer_ordering< Review Comment: Moved this function under `datafusion_physical_expr::utils` -- 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...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org