Skip to main content

partiql_eval/
error.rs

1use crate::eval::evaluable::Evaluable;
2use crate::eval::expr::EvalExpr;
3use crate::eval::EvalContext;
4use partiql_catalog::extension::ExtensionResultError;
5use partiql_value::datum::RefTupleView;
6use partiql_value::Value;
7use std::borrow::Cow;
8use thiserror::Error;
9
10/// All errors that occurred during [`partiql_logical::LogicalPlan`] to [`eval::EvalPlan`] creation.
11#[derive(Debug)]
12pub struct PlanErr {
13    pub errors: Vec<PlanningError>,
14}
15
16/// An error that can happen during [`partiql_logical::LogicalPlan`] to [`eval::EvalPlan`] creation.
17#[derive(Error, Debug, Clone, PartialEq, Eq, Hash)]
18#[non_exhaustive]
19pub enum PlanningError {
20    /// Feature has not yet been implemented.
21    #[error("Not yet implemented: {0}")]
22    NotYetImplemented(String),
23    /// Internal error that was not due to user input or API violation.
24    #[error("Illegal State: {0}")]
25    IllegalState(String),
26}
27
28/// All errors that occurred during evaluation.
29#[derive(Debug)]
30pub struct EvalErr {
31    pub errors: Vec<EvaluationError>,
32}
33
34/// An error that can happen during evaluation.
35#[derive(Error, Debug)]
36#[non_exhaustive]
37pub enum EvaluationError {
38    /// Internal error that was not due to user input or API violation.
39    #[error("Illegal State: {0}")]
40    IllegalState(String),
41    /// Malformed evaluation plan with graph containing cycle.
42    #[error("Evaluation Error: invalid evaluation plan detected `{0}`")]
43    InvalidEvaluationPlan(String),
44    /// Feature has not yet been implemented.
45    #[error("Not yet implemented: {0}")]
46    NotYetImplemented(String),
47
48    /// Error originating in an extension
49    #[error("Extension Result Expression Error")]
50    ExtensionResultError(#[from] ExtensionResultError),
51}
52
53/// Used when an error occurs during the logical to eval plan conversion. Allows the conversion
54/// to continue in order to report multiple errors.
55#[derive(Debug)]
56pub(crate) struct ErrorNode {}
57
58impl ErrorNode {
59    pub(crate) fn new() -> ErrorNode {
60        ErrorNode {}
61    }
62}
63
64impl Evaluable for ErrorNode {
65    fn evaluate(&self, _: [Option<Value>; 2], _ctx: &dyn EvalContext) -> Value {
66        panic!("ErrorNode will not be evaluated")
67    }
68}
69
70impl EvalExpr for ErrorNode {
71    fn evaluate<'a, 'c, 'o>(
72        &'a self,
73        _bindings: &'a dyn RefTupleView<'a, Value>,
74        _ctx: &'c dyn EvalContext,
75    ) -> Cow<'o, Value>
76    where
77        'c: 'a,
78        'a: 'o,
79    {
80        panic!("ErrorNode will not be evaluated")
81    }
82}