Skip to content

Commit 58ed702

Browse files
authored
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
1 parent 2ac0842 commit 58ed702

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

datafusion/sql/src/unparser/plan.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -528,24 +528,10 @@ impl Unparser<'_> {
528528
fn sort_to_sql(&self, sort_exprs: Vec<Expr>) -> Result<Vec<ast::OrderByExpr>> {
529529
sort_exprs
530530
.iter()
531-
.map(|expr: &Expr| match expr {
532-
Expr::Sort(sort_expr) => {
533-
let col = self.expr_to_sql(&sort_expr.expr)?;
534-
535-
let nulls_first = if self.dialect.supports_nulls_first_in_sort() {
536-
Some(sort_expr.nulls_first)
537-
} else {
538-
None
539-
};
540-
541-
Ok(ast::OrderByExpr {
542-
asc: Some(sort_expr.asc),
543-
expr: col,
544-
nulls_first,
545-
with_fill: None,
546-
})
547-
}
548-
_ => plan_err!("Expecting Sort expr"),
531+
.map(|expr: &Expr| {
532+
self.expr_to_unparsed(expr)?
533+
.into_order_by_expr()
534+
.or(plan_err!("Expecting Sort expr"))
549535
})
550536
.collect::<Result<Vec<_>>>()
551537
}

0 commit comments

Comments
 (0)