partiql_eval/eval/expr/
mod.rs

1mod base_table;
2pub(crate) use base_table::*;
3mod coll;
4pub(crate) use coll::*;
5mod control_flow;
6pub(crate) use control_flow::*;
7mod data_types;
8pub(crate) use data_types::*;
9mod datetime;
10pub(crate) use datetime::*;
11mod strings;
12pub(crate) use strings::*;
13mod path;
14pub(crate) use path::*;
15mod pattern_match;
16pub(crate) use pattern_match::*;
17
18mod graph_match;
19pub(crate) use graph_match::*;
20mod functions;
21mod operators;
22
23pub(crate) use operators::*;
24
25use crate::eval::EvalContext;
26
27use partiql_value::datum::{DatumLowerError, RefTupleView};
28use partiql_value::Value;
29use std::borrow::Cow;
30use std::fmt::Debug;
31use thiserror::Error;
32
33/// A trait for expressions that require evaluation, e.g. `a + b` or `c > 2`.
34pub trait EvalExpr: Debug {
35    fn evaluate<'a, 'c, 'o>(
36        &'a self,
37        bindings: &'a dyn RefTupleView<'a, Value>,
38        ctx: &'c dyn EvalContext,
39    ) -> Cow<'o, Value>
40    where
41        'c: 'a,
42        'a: 'o;
43}
44
45#[derive(Error, Debug)]
46#[non_exhaustive]
47/// An error in binding an expression for evaluation
48pub enum BindError {
49    #[error("Argument number mismatch: expected one of `{expected:?}`, found `{found}` ")]
50    ArgNumMismatch { expected: Vec<usize>, found: usize },
51
52    /// Feature has not yet been implemented.
53    #[error("Argument constraint not satisfied: `{0}`")]
54    ArgumentConstraint(String),
55
56    /// Feature has not yet been implemented.
57    #[error("Not yet implemented: {0}")]
58    NotYetImplemented(String),
59
60    #[error("Error lowering literal value: {0}")]
61    LiteralValue(#[from] DatumLowerError),
62
63    /// Any other error.
64    #[error("Bind error: unknown error")]
65    Unknown,
66}
67
68/// A trait for binding an expression to its arguments into an `EvalExpr`
69pub trait BindEvalExpr: Debug {
70    fn bind<const STRICT: bool>(
71        self,
72        args: Vec<Box<dyn EvalExpr>>,
73    ) -> Result<Box<dyn EvalExpr>, BindError>;
74}