icydb_core/db/query/
expr.rs1use crate::db::query::{
2 plan::{OrderDirection, OrderSpec, PlanError, validate::validate_order},
3 predicate::{self, Predicate, SchemaInfo, ValidateError, normalize, normalize_enum_literals},
4};
5use thiserror::Error as ThisError;
6
7#[derive(Clone, Debug)]
14pub struct FilterExpr(pub Predicate);
15
16impl FilterExpr {
17 pub(crate) fn lower_with(&self, schema: &SchemaInfo) -> Result<Predicate, ValidateError> {
19 let normalized_enum_literals = normalize_enum_literals(schema, &self.0)?;
20 predicate::validate::reject_unsupported_query_features(&normalized_enum_literals)?;
21 predicate::validate(schema, &normalized_enum_literals)?;
22
23 Ok(normalize(&normalized_enum_literals))
24 }
25}
26
27#[derive(Clone, Debug)]
34pub struct SortExpr {
35 pub fields: Vec<(String, OrderDirection)>,
36}
37
38impl SortExpr {
39 pub(crate) fn lower_with(&self, schema: &SchemaInfo) -> Result<OrderSpec, SortLowerError> {
41 let spec = OrderSpec {
42 fields: self.fields.clone(),
43 };
44
45 validate_order(schema, &spec)?;
46
47 Ok(spec)
48 }
49}
50
51#[derive(Debug, ThisError)]
57pub(crate) enum SortLowerError {
58 #[error("{0}")]
59 Validate(#[from] ValidateError),
60
61 #[error("{0}")]
62 Plan(Box<PlanError>),
63}
64
65impl From<PlanError> for SortLowerError {
66 fn from(err: PlanError) -> Self {
67 Self::Plan(Box::new(err))
68 }
69}