Skip to content

Commit

Permalink
Deduplicate sort unparsing logic (#12175)
Browse files Browse the repository at this point in the history
* Deduplicate sort unparsing logic

Reconstruction of `ast::OrderByExpr` was implemented twice, in `plan.rs`
and `expr.rs` submodules of the unparser.

* empty
  • Loading branch information
findepi authored Aug 27, 2024
1 parent 2ac0842 commit 58ed702
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions datafusion/sql/src/unparser/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>>>()
}
Expand Down

0 comments on commit 58ed702

Please sign in to comment.