You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/12/31 02:45:12 UTC

[GitHub] [arrow-datafusion] Jimexist commented on a change in pull request #1506: Fix ORDER BY on aggregate

Jimexist commented on a change in pull request #1506:
URL: https://github.com/apache/arrow-datafusion/pull/1506#discussion_r776912209



##########
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:
       i guess you can use `..` to ignore these fields?




-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org