This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 58ed702c8f Deduplicate sort unparsing logic (#12175)
58ed702c8f is described below

commit 58ed702c8f7f2536a8f71cf8b7486812a3afa42d
Author: Piotr Findeisen <[email protected]>
AuthorDate: Tue Aug 27 15:17:23 2024 +0200

    Deduplicate sort unparsing logic (#12175)
    
    * Deduplicate sort unparsing logic
    
    Reconstruction of `ast::OrderByExpr` was implemented twice, in `plan.rs`
    and `expr.rs` submodules of the unparser.
    
    * empty
---
 datafusion/sql/src/unparser/plan.rs | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/datafusion/sql/src/unparser/plan.rs 
b/datafusion/sql/src/unparser/plan.rs
index 8b5a5b0942..106705c322 100644
--- a/datafusion/sql/src/unparser/plan.rs
+++ b/datafusion/sql/src/unparser/plan.rs
@@ -528,24 +528,10 @@ impl Unparser<'_> {
     fn sort_to_sql(&self, sort_exprs: Vec<Expr>) -> 
Result<Vec<ast::OrderByExpr>> {
         sort_exprs
             .iter()
-            .map(|expr: &Expr| match expr {
-                Expr::Sort(sort_expr) => {
-                    let col = self.expr_to_sql(&sort_expr.expr)?;
-
-                    let nulls_first = if 
self.dialect.supports_nulls_first_in_sort() {
-                        Some(sort_expr.nulls_first)
-                    } else {
-                        None
-                    };
-
-                    Ok(ast::OrderByExpr {
-                        asc: Some(sort_expr.asc),
-                        expr: col,
-                        nulls_first,
-                        with_fill: None,
-                    })
-                }
-                _ => plan_err!("Expecting Sort expr"),
+            .map(|expr: &Expr| {
+                self.expr_to_unparsed(expr)?
+                    .into_order_by_expr()
+                    .or(plan_err!("Expecting Sort expr"))
             })
             .collect::<Result<Vec<_>>>()
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to