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