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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use crate::base::{database::ColumnType, math::decimal::DecimalError};
use alloc::string::String;
use core::result::Result;
use snafu::Snafu;
/// Errors from operations on columns.
#[derive(Snafu, Debug, PartialEq, Eq)]
pub enum ColumnOperationError {
/// Two columns do not have the same length
#[snafu(display("Columns have different lengths: {len_a} != {len_b}"))]
DifferentColumnLength {
/// The length of the first column
len_a: usize,
/// The length of the second column
len_b: usize,
},
/// Incorrect `ColumnType` in binary operations
#[snafu(display("{operator:?}(lhs: {left_type:?}, rhs: {right_type:?}) is not supported"))]
BinaryOperationInvalidColumnType {
/// Binary operator that caused the error
operator: String,
/// `ColumnType` of left operand
left_type: ColumnType,
/// `ColumnType` of right operand
right_type: ColumnType,
},
/// Incorrect `ColumnType` in unary operations
#[snafu(display("{operator:?}(operand: {operand_type:?}) is not supported"))]
UnaryOperationInvalidColumnType {
/// Unary operator that caused the error
operator: String,
/// `ColumnType` of the operand
operand_type: ColumnType,
},
/// Overflow in integer operations
#[snafu(display("Overflow in integer operation: {error}"))]
IntegerOverflow {
/// The underlying overflow error
error: String,
},
/// Division by zero
#[snafu(display("Division by zero"))]
DivisionByZero,
/// Errors related to decimal operations
#[snafu(transparent)]
DecimalConversionError {
/// The underlying source error
source: DecimalError,
},
/// Errors related to unioning columns of different types
#[snafu(display(
"Cannot union columns of different types: {correct_type:?} and {actual_type:?}"
))]
UnionDifferentTypes {
/// The correct data type
correct_type: ColumnType,
/// The type of the column that caused the error
actual_type: ColumnType,
},
/// Errors related to index out of bounds
#[snafu(display("Index out of bounds: {index} >= {len}"))]
IndexOutOfBounds {
/// The index that caused the error
index: usize,
/// The length of the column
len: usize,
},
/// Errors related to casting between signed and unsigned types. This error can be
/// used as a signal that a casting operation is currently unsupported.
/// For example, an i8 can fit inside of a u8 iff it is greater than zero. The library
/// needs to have a way to check *and* prove that this condition is true. If the library
/// does not have a proving mechanism in place for this check, then this error is
/// then used to indicate that the operation is not supported.
#[snafu(display("Cannot fit {left_type} into {right_type} without losing data"))]
SignedCastingError {
/// `ColumnType` of left operand
left_type: ColumnType,
/// `ColumnType` of right operand
right_type: ColumnType,
},
/// Errors related to casting between two types.
#[snafu(display("Cannot fit {left_type} into {right_type} without losing data"))]
CastingError {
/// `ColumnType` of left operand
left_type: ColumnType,
/// `ColumnType` of right operand
right_type: ColumnType,
},
/// Errors related to casting with scaling between two types.
#[snafu(display("Cannot fit {left_type} into {right_type} without losing data"))]
ScaleCastingError {
/// `ColumnType` of left operand
left_type: ColumnType,
/// `ColumnType` of right operand
right_type: ColumnType,
},
}
/// Result type for column operations
pub type ColumnOperationResult<T> = Result<T, ColumnOperationError>;