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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use {
crate::{ast::DataType, ast::DateTimeField, data::Value},
serde::Serialize,
std::fmt::Debug,
strum_macros::Display,
thiserror::Error,
};
#[derive(Error, Serialize, Debug, PartialEq)]
pub enum ValueError {
#[error("literal: {literal} is incompatible with data type: {data_type:?}")]
IncompatibleLiteralForDataType {
data_type: DataType,
literal: String,
},
#[error("incompatible data type, data type: {data_type:#?}, value: {value:#?}")]
IncompatibleDataType { data_type: DataType, value: Value },
#[error("null value on not null field")]
NullValueOnNotNullField,
#[error("failed to parse number")]
FailedToParseNumber,
#[error("failed to convert Float to Decimal: {0}")]
FloatToDecimalConversionFailure(f64),
#[error("failed to parse date: {0}")]
FailedToParseDate(String),
#[error("failed to parse timestamp: {0}")]
FailedToParseTimestamp(String),
#[error("failed to parse time: {0}")]
FailedToParseTime(String),
#[error("failed to UUID: {0}")]
FailedToParseUUID(String),
#[error("failed to parse Decimal: {0}")]
FailedToParseDecimal(String),
#[error("non-numeric values {lhs:?} {operator} {rhs:?}")]
NonNumericMathOperation {
lhs: Value,
rhs: Value,
operator: NumericBinaryOperator,
},
#[error("the divisor should not be zero")]
DivisorShouldNotBeZero,
#[error("{0} type cannot be grouped by")]
GroupByNotSupported(String),
#[error("unary plus operation for non numeric value")]
UnaryPlusOnNonNumeric,
#[error("unary minus operation for non numeric value")]
UnaryMinusOnNonNumeric,
#[error("unary factorial operation for non numeric value")]
FactorialOnNonNumeric,
#[error("unary factorial operation for non integer value")]
FactorialOnNonInteger,
#[error("unary factorial operation for negative numeric value")]
FactorialOnNegativeNumeric,
#[error("unary factorial operation overflow")]
FactorialOverflow,
#[error("unreachable failure on parsing number")]
UnreachableNumberParsing,
#[error("conflict - unique constraint cannot be used for {0} type")]
ConflictDataTypeOnUniqueConstraint(String),
#[error("impossible cast")]
ImpossibleCast,
#[error("unimplemented cast")]
UnimplementedCast,
#[error("literal cast failed from text to integer: {0}")]
LiteralCastFromTextToIntegerFailed(String),
#[error("literal cast failed from text to float: {0}")]
LiteralCastFromTextToFloatFailed(String),
#[error("literal cast failed from text to decimal: {0}")]
LiteralCastFromTextToDecimalFailed(String),
#[error("literal cast failed to boolean: {0}")]
LiteralCastToBooleanFailed(String),
#[error("literal cast failed to date: {0}")]
LiteralCastToDateFailed(String),
#[error("literal cast failed to Int(8): {0}")]
LiteralCastToInt8Failed(String),
#[error("literal cast failed to time: {0}")]
LiteralCastToTimeFailed(String),
#[error("literal cast failed to timestamp: {0}")]
LiteralCastToTimestampFailed(String),
#[error("unreachable literal cast from number to integer: {0}")]
UnreachableLiteralCastFromNumberToInteger(String),
#[error("unreachable literal cast from number to float: {0}")]
UnreachableLiteralCastFromNumberToFloat(String),
#[error("unimplemented literal cast: {literal} as {data_type:?}")]
UnimplementedLiteralCast {
data_type: DataType,
literal: String,
},
#[error("unreachable integer overflow: {0}")]
UnreachableIntegerOverflow(String),
#[error("operator doesn't exist: {0:?} LIKE {1:?}")]
LikeOnNonString(Value, Value),
#[error("extract format not matched: {value:?} FROM {field:?})")]
ExtractFormatNotMatched { value: Value, field: DateTimeField },
#[error("operator doesn't exist: {0:?} ILIKE {1:?}")]
ILikeOnNonString(Value, Value),
#[error("big endian export not supported for {0} type")]
BigEndianExportNotSupported(String),
#[error("invalid json string")]
InvalidJsonString,
#[error("json object type is required")]
JsonObjectTypeRequired,
#[error("json array type is required")]
JsonArrayTypeRequired,
#[error("unreachable - failed to parse json number: {0}")]
UnreachableJsonNumberParseFailure(String),
#[error("selector requires MAP or LIST types")]
SelectorRequiresMapOrListTypes,
#[error("overflow occurred: {lhs:?} {operator} {rhs:?}")]
BinaryOperationOverflow {
lhs: Value,
rhs: Value,
operator: NumericBinaryOperator,
},
}
#[derive(Debug, PartialEq, Eq, Serialize, Display)]
pub enum NumericBinaryOperator {
#[strum(to_string = "+")]
Add,
#[strum(to_string = "-")]
Subtract,
#[strum(to_string = "*")]
Multiply,
#[strum(to_string = "/")]
Divide,
#[strum(to_string = "%")]
Modulo,
}