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