icydb_core/db/query/
expr.rs1use crate::db::query::plan::{OrderDirection, PlanError, validate::validate_order};
7use crate::db::{
8 predicate::{
9 Predicate, SchemaInfo, ValidateError, normalize, normalize_enum_literals,
10 reject_unsupported_query_features, validate,
11 },
12 query::plan::OrderSpec,
13};
14use thiserror::Error as ThisError;
15
16#[derive(Clone, Debug)]
23pub struct FilterExpr(pub Predicate);
24
25impl FilterExpr {
26 pub(crate) fn lower_with(&self, schema: &SchemaInfo) -> Result<Predicate, ValidateError> {
28 let normalized_enum_literals = normalize_enum_literals(schema, &self.0)?;
30
31 reject_unsupported_query_features(&normalized_enum_literals)?;
33 validate(schema, &normalized_enum_literals)?;
34
35 Ok(normalize(&normalized_enum_literals))
37 }
38}
39
40#[derive(Clone, Debug)]
47pub struct SortExpr {
48 fields: Vec<(String, OrderDirection)>,
49}
50
51impl SortExpr {
52 #[must_use]
54 pub const fn new(fields: Vec<(String, OrderDirection)>) -> Self {
55 Self { fields }
56 }
57
58 #[must_use]
60 pub fn fields(&self) -> &[(String, OrderDirection)] {
61 &self.fields
62 }
63
64 pub(crate) fn lower_with(&self, schema: &SchemaInfo) -> Result<OrderSpec, SortLowerError> {
66 let spec = OrderSpec {
67 fields: self.fields.clone(),
68 };
69
70 validate_order(schema, &spec)?;
71
72 Ok(spec)
73 }
74}
75
76#[derive(Debug, ThisError)]
82pub(crate) enum SortLowerError {
83 #[error("{0}")]
84 Validate(#[from] ValidateError),
85
86 #[error("{0}")]
87 Plan(Box<PlanError>),
88}
89
90impl From<PlanError> for SortLowerError {
91 fn from(err: PlanError) -> Self {
92 Self::Plan(Box::new(err))
93 }
94}