viirya commented on a change in pull request #1506:
URL: https://github.com/apache/arrow-datafusion/pull/1506#discussion_r776923345
##########
File path: datafusion/src/logical_plan/expr.rs
##########
@@ -1317,6 +1319,83 @@ pub fn normalize_cols(
.collect()
}
+/// Rewrite sort on aggregate expressions to sort on the column of aggregate
output
+#[inline]
+pub fn rewrite_sort_cols_by_aggs(
+ exprs: impl IntoIterator<Item = impl Into<Expr>>,
+ plan: &LogicalPlan,
+) -> Result<Vec<Expr>> {
+ exprs
+ .into_iter()
+ .map(|e| {
+ let expr = e.into();
+ match expr.clone() {
+ Expr::Sort {
+ expr,
+ asc,
+ nulls_first,
+ } => {
+ let sort = Expr::Sort {
+ expr: Box::new(rewrite_sort_col_by_aggs(*expr, plan)?),
+ asc,
+ nulls_first,
+ };
+ Ok(sort)
+ }
+ _ => Ok(expr),
+ }
+ })
+ .collect()
+}
+
+fn rewrite_sort_col_by_aggs(expr: Expr, plan: &LogicalPlan) -> Result<Expr> {
+ match plan {
+ LogicalPlan::Aggregate(Aggregate {
+ input,
+ group_expr: _,
+ aggr_expr,
+ schema: _,
Review comment:
yea. i will use it.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]