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 unioning fewer than 2 tables.
21    #[snafu(display("Cannot union fewer than 2 tables"))]
22    UnionNotEnoughTables,
23    /// Errors related to joining tables with different numbers of columns.
24    #[snafu(display(
25        "Cannot join tables with different numbers of columns: {left_num_columns} and {right_num_columns}"
26    ))]
27    JoinWithDifferentNumberOfColumns {
28        /// The number of columns in the left-hand table
29        left_num_columns: usize,
30        /// The number of columns in the right-hand table
31        right_num_columns: usize,
32    },
33    /// Errors related to joining tables on columns with incompatible types.
34    #[snafu(display(
35        "Cannot join tables on columns with incompatible types: {left_type:?} and {right_type:?}"
36    ))]
37    JoinIncompatibleTypes {
38        /// The left-hand side data type
39        left_type: ColumnType,
40        /// The right-hand side data type
41        right_type: ColumnType,
42    },
43    /// Errors related to a column that does not exist in a table.
44    #[snafu(display("Column {column_ident:?} does not exist in table"))]
45    ColumnDoesNotExist {
46        /// The nonexistent column identifier
47        column_ident: Ident,
48    },
49    /// Errors related to duplicate columns in a table.
50    #[snafu(display("Some column is duplicated in table"))]
51    DuplicateColumn,
52    /// Errors due to bad column operations.
53    #[snafu(transparent)]
54    ColumnOperationError {
55        /// The underlying `ColumnOperationError`
56        source: ColumnOperationError,
57    },
58    /// Errors related to column index out of bounds.
59    #[snafu(display("Column index out of bounds: {column_index}"))]
60    ColumnIndexOutOfBounds {
61        /// The column index that is out of bounds
62        column_index: usize,
63    },
64}
65
66/// Result type for table operations
67pub type TableOperationResult<T> = Result<T, TableOperationError>;