proof_of_sql_planner/
error.rs

1use arrow::datatypes::DataType;
2use datafusion::{
3    common::DataFusionError,
4    logical_expr::{
5        expr::{AggregateFunction, Placeholder},
6        Expr, LogicalPlan, Operator,
7    },
8    physical_plan,
9};
10use proof_of_sql::{base::math::decimal::DecimalError, sql::AnalyzeError};
11use snafu::Snafu;
12use sqlparser::parser::ParserError;
13
14/// Proof of SQL Planner error
15#[derive(Debug, Snafu)]
16pub enum PlannerError {
17    /// Returned when the internal analyze process fails
18    #[snafu(transparent)]
19    AnalyzeError {
20        /// Underlying analyze error
21        source: AnalyzeError,
22    },
23    /// Returned when a decimal error occurs
24    #[snafu(transparent)]
25    DecimalError {
26        /// Underlying decimal error
27        source: DecimalError,
28    },
29    /// Returned when sqlparser fails to parse a query
30    #[snafu(transparent)]
31    SqlParserError {
32        /// Underlying sqlparser error
33        source: ParserError,
34    },
35    /// Returned when datafusion fails to plan a query
36    #[snafu(transparent)]
37    DataFusionError {
38        /// Underlying datafusion error
39        source: DataFusionError,
40    },
41    /// Returned if a column is not found
42    #[snafu(display("Column not found"))]
43    ColumnNotFound,
44    /// Returned if a table is not found
45    #[snafu(display("Table not found: {}", table_name))]
46    TableNotFound {
47        /// Table name
48        table_name: String,
49    },
50    /// Returned when a placeholder id is invalid
51    #[snafu(display("Placeholder id {id:?} is invalid"))]
52    InvalidPlaceholderId {
53        /// Unsupported placeholder id
54        id: String,
55    },
56    /// Returned when a placeholder is untyped
57    #[snafu(display("Placeholder {placeholder:?} is untyped"))]
58    UntypedPlaceholder {
59        /// Untyped placeholder
60        placeholder: Placeholder,
61    },
62    /// Returned when a datatype is not supported
63    #[snafu(display("Unsupported datatype: {}", data_type))]
64    UnsupportedDataType {
65        /// Unsupported datatype
66        data_type: DataType,
67    },
68    /// Returned when a binary operator is not supported
69    #[snafu(display("Binary operator {} is not supported", op))]
70    UnsupportedBinaryOperator {
71        /// Unsupported binary operation
72        op: Operator,
73    },
74    /// Returned when the aggregate opetation is not supported
75    #[snafu(display("Aggregate operation {op:?} is not supported"))]
76    UnsupportedAggregateOperation {
77        /// Unsupported aggregate operation
78        op: physical_plan::aggregates::AggregateFunction,
79    },
80    /// Returned when the `AggregateFunction` is not supported
81    #[snafu(display("AggregateFunction {function:?} is not supported"))]
82    UnsupportedAggregateFunction {
83        /// Unsupported `AggregateFunction`
84        function: AggregateFunction,
85    },
86    /// Returned when a logical expression is not resolved
87    #[snafu(display("Logical expression {:?} is not supported", expr))]
88    UnsupportedLogicalExpression {
89        /// Unsupported logical expression
90        expr: Box<Expr>,
91    },
92    /// Returned when a `LogicalPlan` is not supported
93    #[snafu(display("LogicalPlan is not supported"))]
94    UnsupportedLogicalPlan {
95        /// Unsupported `LogicalPlan`
96        plan: Box<LogicalPlan>,
97    },
98    /// Returned when the `LogicalPlan` is not resolved
99    #[snafu(display("LogicalPlan is not resolved"))]
100    UnresolvedLogicalPlan,
101    /// Returned when catalog is provided since it is not supported
102    #[snafu(display("Catalog is not supported"))]
103    CatalogNotSupported,
104    /// Returned when error occurs in postprocessing
105    #[snafu(transparent)]
106    PostprocessingError {
107        /// Underlying postprocessing error
108        source: super::postprocessing::PostprocessingError,
109    },
110}
111
112/// Proof of SQL Planner result
113pub type PlannerResult<T> = Result<T, PlannerError>;