icydb_core/db/query/
expr.rs1use crate::db::query::{
2 plan::{OrderDirection, OrderSpec, PlanError, validate::validate_order},
3 predicate::{self, Predicate, SchemaInfo, ValidateError, normalize},
4};
5use thiserror::Error as ThisError;
6
7#[derive(Clone, Debug)]
14pub struct FilterExpr(pub Predicate);
15
16impl FilterExpr {
17 pub fn lower_with(&self, schema: &SchemaInfo) -> Result<Predicate, ValidateError> {
19 predicate::validate(schema, &self.0)?;
20
21 Ok(normalize(&self.0))
22 }
23}
24
25#[derive(Clone, Debug)]
32pub struct SortExpr {
33 pub fields: Vec<(String, OrderDirection)>,
34}
35
36impl SortExpr {
37 pub fn lower_with(&self, schema: &SchemaInfo) -> Result<OrderSpec, SortLowerError> {
39 let spec = OrderSpec {
40 fields: self.fields.clone(),
41 };
42
43 validate_order(schema, &spec)?;
44
45 Ok(spec)
46 }
47}
48
49#[derive(Debug, ThisError)]
55pub enum SortLowerError {
56 #[error("{0}")]
57 Validate(#[from] ValidateError),
58
59 #[error("{0}")]
60 Plan(#[from] PlanError),
61}