proof_of_sql/base/database/
table_operation_error.rs

1use super::{ColumnField, ColumnOperationError, ColumnType};
2use alloc::vec::Vec;
3use core::result::Result;
4use snafu::Snafu;
5use sqlparser::ast::Ident;
6
7/// Errors from operations on tables.
8#[derive(Snafu, Debug, PartialEq, Eq)]
9pub enum TableOperationError {
10    /// Errors related to unioning tables with incompatible schemas.
11    #[snafu(display(
12        "Cannot union tables with incompatible schemas: {correct_schema:?} and {actual_schema:?}"
13    ))]
14    UnionIncompatibleSchemas {
15        /// The correct data type
16        correct_schema: Vec<ColumnField>,
17        /// The schema of the table that caused the error
18        actual_schema: Vec<ColumnField>,
19    },
20    /// Errors related to joining tables with different numbers of columns.
21    #[snafu(display(
22        "Cannot join tables with different numbers of columns: {left_num_columns} and {right_num_columns}"
23    ))]
24    JoinWithDifferentNumberOfColumns {
25        /// The number of columns in the left-hand table
26        left_num_columns: usize,
27        /// The number of columns in the right-hand table
28        right_num_columns: usize,
29    },
30    /// Errors related to joining tables on columns with incompatible types.
31    #[snafu(display(
32        "Cannot join tables on columns with incompatible types: {left_type:?} and {right_type:?}"
33    ))]
34    JoinIncompatibleTypes {
35        /// The left-hand side data type
36        left_type: ColumnType,
37        /// The right-hand side data type
38        right_type: ColumnType,
39    },
40    /// Errors related to a column that does not exist in a table.
41    #[snafu(display("Column {column_ident:?} does not exist in table"))]
42    ColumnDoesNotExist {
43        /// The nonexistent column identifier
44        column_ident: Ident,
45    },
46    /// Errors related to duplicate columns in a table.
47    #[snafu(display("Some column is duplicated in table"))]
48    DuplicateColumn,
49    /// Errors due to bad column operations.
50    #[snafu(transparent)]
51    ColumnOperationError {
52        /// The underlying `ColumnOperationError`
53        source: ColumnOperationError,
54    },
55    /// Errors related to column index out of bounds.
56    #[snafu(display("Column index out of bounds: {column_index}"))]
57    ColumnIndexOutOfBounds {
58        /// The column index that is out of bounds
59        column_index: usize,
60    },
61}
62
63/// Result type for table operations
64pub type TableOperationResult<T> = Result<T, TableOperationError>;