fnck_sql/planner/operator/
limit.rs1use super::Operator;
2use crate::planner::{Childrens, LogicalPlan};
3use fnck_sql_serde_macros::ReferenceSerialization;
4use std::fmt;
5use std::fmt::Formatter;
6
7#[derive(Debug, PartialEq, Eq, Clone, Hash, ReferenceSerialization)]
8pub struct LimitOperator {
9 pub offset: Option<usize>,
10 pub limit: Option<usize>,
11}
12
13impl LimitOperator {
14 pub fn build(
15 offset: Option<usize>,
16 limit: Option<usize>,
17 children: LogicalPlan,
18 ) -> LogicalPlan {
19 LogicalPlan::new(
20 Operator::Limit(LimitOperator { offset, limit }),
21 Childrens::Only(children),
22 )
23 }
24}
25
26impl fmt::Display for LimitOperator {
27 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
28 if let Some(limit) = self.limit {
29 write!(f, "Limit {}", limit)?;
30 }
31 if self.limit.is_some() && self.offset.is_some() {
32 write!(f, ", ")?;
33 }
34 if let Some(offset) = self.offset {
35 write!(f, "Offset {}", offset)?;
36 }
37
38 Ok(())
39 }
40}