gluesql_core/executor/evaluate/
error.rs1use {
2 crate::{
3 ast::{BinaryOperator, DataType, ToSql},
4 plan::AggregateExprPlan,
5 },
6 serde::Serialize,
7 std::fmt::Debug,
8 thiserror::Error,
9};
10
11#[derive(Error, Serialize, Debug, PartialEq, Eq)]
12pub enum EvaluateError {
13 #[error("{0}")]
14 FormatParseError(String),
15
16 #[error("literal add on non-numeric")]
17 LiteralAddOnNonNumeric,
18
19 #[error("function requires string value: {0}")]
20 FunctionRequiresStringValue(String),
21
22 #[error("function requires integer or string value: {0}")]
23 FunctionRequiresIntegerOrStringValue(String),
24
25 #[error("arrow base requires MAP or LIST types")]
26 ArrowBaseRequiresMapOrList,
27
28 #[error("arrow selector requires integer or string value: {0}")]
29 ArrowSelectorRequiresIntegerOrString(String),
30
31 #[error("function requires integer value: {0}")]
32 FunctionRequiresIntegerValue(String),
33
34 #[error("function requires float or integer value: {0}")]
35 FunctionRequiresFloatOrIntegerValue(String),
36
37 #[error("function requires usize value: {0}")]
38 FunctionRequiresUSizeValue(String),
39
40 #[error("function requires float value: {0}")]
41 FunctionRequiresFloatValue(String),
42
43 #[error("extract format does not support value: {0}")]
44 ExtractFormatNotMatched(String),
45
46 #[error("function requires map value: {0}")]
47 FunctionRequiresMapValue(String),
48
49 #[error("function requires point value: {0}")]
50 FunctionRequiresPointValue(String),
51
52 #[error("function requires date or datetime value: {0}")]
53 FunctionRequiresDateOrDateTimeValue(String),
54
55 #[error("function requires one of string, list, map types: {0}")]
56 FunctionRequiresStrOrListOrMapValue(String),
57
58 #[error("identifier not found: {0}")]
59 IdentifierNotFound(String),
60
61 #[error("identifier not found: {table_alias}.{column_name}")]
62 CompoundIdentifierNotFound {
63 table_alias: String,
64 column_name: String,
65 },
66
67 #[error("only boolean value is accepted: {0}")]
68 BooleanTypeRequired(String),
69
70 #[error("expr requires map or list value")]
71 MapOrListTypeRequired,
72
73 #[error("expr requires map value")]
74 MapTypeRequired,
75
76 #[error("expr requires list value")]
77 ListTypeRequired,
78
79 #[error("all elements in the list must be comparable to each other")]
80 InvalidSortType,
81
82 #[error("sort order must be either ASC or DESC")]
83 InvalidSortOrder,
84
85 #[error("map or string value required for json map conversion: {0}")]
86 MapOrStringValueRequired(String),
87
88 #[error("text literal required for json map conversion: {0}")]
89 TextLiteralRequired(String),
90
91 #[error("subquery is not allowed in stateless expression")]
92 SubqueryNotAllowedInStatelessExpr,
93
94 #[error("IN (subquery) is not allowed in stateless expression")]
95 InSubqueryNotAllowedInStatelessExpr,
96
97 #[error("EXISTS (subquery) is not allowed in stateless expression")]
98 ExistsSubqueryNotAllowedInStatelessExpr,
99
100 #[error("row context is required for identifier evaluation: {0}")]
101 IdentifierRequiresRowContext(String),
102
103 #[error("row context is required for compound identifier evaluation: {alias}.{ident}")]
104 CompoundIdentifierRequiresRowContext { alias: String, ident: String },
105
106 #[error("aggregate slot value missing: {0:?}")]
107 AggregateSlotValueMissing(Box<AggregateExprPlan>),
108
109 #[error("aggregate expression requires planner binding: {0:?}")]
110 UnplannedAggregate(Box<AggregateExprPlan>),
111
112 #[error("incompatible bit operation between {0} and {1}")]
113 IncompatibleBitOperation(String, String),
114
115 #[error("the divisor should not be zero")]
116 DivisorShouldNotBeZero,
117
118 #[error("negative substring length not allowed")]
119 NegativeSubstrLenNotAllowed,
120
121 #[error("subquery returns more than one row")]
122 MoreThanOneRowReturned,
123
124 #[error("subquery returns more than one column")]
125 MoreThanOneColumnReturned,
126
127 #[error("IN (subquery) must return one column")]
128 InSubqueryMustReturnOneColumn,
129
130 #[error("schemaless projection is not allowed for IN (subquery)")]
131 SchemalessProjectionForInSubQuery,
132
133 #[error("schemaless projection is not allowed for subquery")]
134 SchemalessProjectionForSubQuery,
135
136 #[error("format function does not support following data_type: {0}")]
137 UnsupportedExprForFormatFunction(String),
138
139 #[error("support single character only")]
140 AsciiFunctionRequiresSingleCharacterValue,
141
142 #[error("non-ascii character not allowed")]
143 NonAsciiCharacterNotAllowed,
144
145 #[error("function requires integer value in range")]
146 ChrFunctionRequiresIntegerValueInRange0To255,
147
148 #[error("unsupported evaluate binary operation {} {} {}", .left, .op.to_sql(), .right)]
149 UnsupportedBinaryOperation {
150 left: String,
151 op: BinaryOperator,
152 right: String,
153 },
154
155 #[error("unsupported evaluate string unary plus: {0}")]
156 UnsupportedUnaryPlus(String),
157
158 #[error("unsupported evaluate string unary minus: {0}")]
159 UnsupportedUnaryMinus(String),
160
161 #[error("unary factorial requires numeric literal: {0}")]
162 UnaryFactorialRequiresNumericLiteral(String),
163
164 #[error("unary bitwise-not requires integer literal: {0}")]
165 UnaryBitwiseNotRequiresIntegerLiteral(String),
166
167 #[error("operator doesn't exist: {base} {case} {pattern}", case = if *case_sensitive { "LIKE" } else { "ILIKE" })]
168 LikeOnNonStringLiteral {
169 base: String,
170 pattern: String,
171 case_sensitive: bool,
172 },
173
174 #[error("unsupported custom function in subqueries")]
175 UnsupportedCustomFunction,
176
177 #[error(r#"The function "{function_name}" requires at least {required_minimum} argument(s), but {found} were provided."#)]
178 FunctionRequiresMoreArguments {
179 function_name: String,
180 required_minimum: usize,
181 found: usize,
182 },
183
184 #[error(
185 "function args.length not matching: {name}, expected: {expected_minimum} ~ {expected_maximum}, found: {found}"
186 )]
187 FunctionArgsLengthNotWithinRange {
188 name: String,
189 expected_minimum: usize,
190 expected_maximum: usize,
191 found: usize,
192 },
193
194 #[error("unsupported function: {0}")]
195 UnsupportedFunction(String),
196
197 #[error("The provided arguments are non-comparable: {0}")]
198 NonComparableArgumentError(String),
199
200 #[error("function requires at least one argument: {0}")]
201 FunctionRequiresAtLeastOneArgument(String),
202
203 #[error("function CONCAT requires at least 1 argument")]
204 EmptyArgNotAllowedInConcat,
205
206 #[error("LCM calculation resulted in a value out of the i64 range")]
207 LcmResultOutOfRange,
208
209 #[error("GCD or LCM calculation overflowed on trying to get the absolute value of {0}")]
210 GcdLcmOverflow(i64),
211
212 #[error("failed to convert Value to u32: {0}")]
213 I64ToU32ConversionFailure(String),
214
215 #[error("failed to parse number {literal:?} to {data_type}")]
216 NumberParseFailed {
217 literal: String,
218 data_type: DataType,
219 },
220
221 #[error("failed to cast number {literal:?} to {data_type}")]
222 NumberCastFailed {
223 literal: String,
224 data_type: DataType,
225 },
226
227 #[error("failed to parse text {literal:?} to {data_type}")]
228 TextParseFailed {
229 literal: String,
230 data_type: DataType,
231 },
232
233 #[error("failed to cast text {literal:?} to {data_type}")]
234 TextCastFailed {
235 literal: String,
236 data_type: DataType,
237 },
238}