quill_sql/plan/logical_plan/
sort.rs

1use crate::expression::Expr;
2use crate::plan::logical_plan::LogicalPlan;
3use std::sync::Arc;
4
5#[derive(derive_new::new, Debug, Clone)]
6pub struct Sort {
7    pub order_by: Vec<OrderByExpr>,
8    pub input: Arc<LogicalPlan>,
9    pub limit: Option<usize>,
10}
11
12#[derive(Clone, PartialEq, Eq, Debug)]
13pub struct OrderByExpr {
14    /// The expression to sort on
15    pub expr: Box<Expr>,
16    /// The direction of the sort
17    pub asc: bool,
18    /// Whether to put Nulls before all other data values
19    pub nulls_first: bool,
20}
21
22impl std::fmt::Display for OrderByExpr {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        write!(
25            f,
26            "{} {} {}",
27            self.expr,
28            if self.asc { "ASC" } else { "DESC" },
29            if self.nulls_first {
30                "NULLS FIRST"
31            } else {
32                "NULLS LAST"
33            }
34        )
35    }
36}
37
38impl std::fmt::Display for Sort {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        write!(
41            f,
42            "Sort: {}",
43            self.order_by
44                .iter()
45                .map(|e| format!("{e}"))
46                .collect::<Vec<_>>()
47                .join(", ")
48        )
49    }
50}