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 pub fields: Vec<(String, OrderDirection)>,
49}
50
51impl SortExpr {
52 pub(crate) fn lower_with(&self, schema: &SchemaInfo) -> Result<OrderSpec, SortLowerError> {
54 let spec = OrderSpec {
55 fields: self.fields.clone(),
56 };
57
58 validate_order(schema, &spec)?;
59
60 Ok(spec)
61 }
62}
63
64#[derive(Debug, ThisError)]
70pub(crate) enum SortLowerError {
71 #[error("{0}")]
72 Validate(#[from] ValidateError),
73
74 #[error("{0}")]
75 Plan(Box<PlanError>),
76}
77
78impl From<PlanError> for SortLowerError {
79 fn from(err: PlanError) -> Self {
80 Self::Plan(Box::new(err))
81 }
82}