1use std::any::Any;
16
17use common_datasource::file_format::Format;
18use common_error::define_into_tonic_status;
19use common_error::ext::{BoxedError, ErrorExt, RetryHint};
20use common_error::status_code::StatusCode;
21use common_macro::stack_trace_debug;
22use common_query::error::Error as QueryResult;
23use datafusion::parquet;
24use datafusion_common::DataFusionError;
25use datatypes::arrow::error::ArrowError;
26use object_store::error::retry_hint_from_opendal_error;
27use snafu::{Location, Snafu};
28use table::metadata::TableType;
29
30#[derive(Snafu)]
31#[snafu(visibility(pub))]
32#[stack_trace_debug]
33pub enum Error {
34 #[snafu(display("Table already exists: `{}`", table))]
35 TableAlreadyExists {
36 table: String,
37 #[snafu(implicit)]
38 location: Location,
39 },
40
41 #[snafu(display("Failed to cast result: `{}`", source))]
42 Cast {
43 #[snafu(source)]
44 source: QueryResult,
45 #[snafu(implicit)]
46 location: Location,
47 },
48
49 #[snafu(display("View already exists: `{name}`"))]
50 ViewAlreadyExists {
51 name: String,
52 #[snafu(implicit)]
53 location: Location,
54 },
55
56 #[snafu(display("Failed to build admin function args: {msg}"))]
57 BuildAdminFunctionArgs { msg: String },
58
59 #[snafu(display("Failed to execute admin function {msg}"))]
60 ExecuteAdminFunction {
61 msg: String,
62 #[snafu(source)]
63 error: DataFusionError,
64 #[snafu(implicit)]
65 location: Location,
66 },
67
68 #[snafu(display("Expected {expected} args, but actual {actual}"))]
69 FunctionArityMismatch { expected: usize, actual: usize },
70
71 #[snafu(display("Failed to invalidate table cache"))]
72 InvalidateTableCache {
73 #[snafu(implicit)]
74 location: Location,
75 source: common_meta::error::Error,
76 },
77
78 #[snafu(display("Failed to execute ddl"))]
79 ExecuteDdl {
80 #[snafu(implicit)]
81 location: Location,
82 source: common_meta::error::Error,
83 },
84
85 #[snafu(display("Unexpected, violated: {}", violated))]
86 Unexpected {
87 violated: String,
88 #[snafu(implicit)]
89 location: Location,
90 },
91
92 #[snafu(display("external error"))]
93 External {
94 #[snafu(implicit)]
95 location: Location,
96 source: BoxedError,
97 },
98
99 #[snafu(display("Failed to insert data"))]
100 RequestInserts {
101 #[snafu(implicit)]
102 location: Location,
103 source: common_meta::error::Error,
104 },
105
106 #[snafu(display("Failed to delete data"))]
107 RequestDeletes {
108 #[snafu(implicit)]
109 location: Location,
110 source: common_meta::error::Error,
111 },
112
113 #[snafu(display("Failed to send request to region"))]
114 RequestRegion {
115 #[snafu(implicit)]
116 location: Location,
117 source: common_meta::error::Error,
118 },
119
120 #[snafu(display("Unsupported region request"))]
121 UnsupportedRegionRequest {
122 #[snafu(implicit)]
123 location: Location,
124 },
125
126 #[snafu(display("Failed to parse SQL"))]
127 ParseSql {
128 #[snafu(implicit)]
129 location: Location,
130 source: sql::error::Error,
131 },
132
133 #[snafu(display("Failed to convert identifier: {}", ident))]
134 ConvertIdentifier {
135 ident: String,
136 #[snafu(implicit)]
137 location: Location,
138 #[snafu(source)]
139 error: datafusion::error::DataFusionError,
140 },
141
142 #[snafu(display("Failed to extract table names"))]
143 ExtractTableNames {
144 #[snafu(implicit)]
145 location: Location,
146 source: query::error::Error,
147 },
148
149 #[snafu(display("Column datatype error"))]
150 ColumnDataType {
151 #[snafu(implicit)]
152 location: Location,
153 source: api::error::Error,
154 },
155
156 #[snafu(display("Invalid column proto definition, column: {}", column))]
157 InvalidColumnDef {
158 column: String,
159 #[snafu(implicit)]
160 location: Location,
161 source: api::error::Error,
162 },
163
164 #[snafu(display("Invalid statement to create view"))]
165 InvalidViewStmt {
166 #[snafu(implicit)]
167 location: Location,
168 },
169
170 #[snafu(display("Expect {expected} columns for view {view_name}, but found {actual}"))]
171 ViewColumnsMismatch {
172 view_name: String,
173 expected: usize,
174 actual: usize,
175 },
176
177 #[snafu(display("Invalid view \"{view_name}\": {msg}"))]
178 InvalidView {
179 msg: String,
180 view_name: String,
181 #[snafu(implicit)]
182 location: Location,
183 },
184
185 #[snafu(display("Failed to convert column default constraint, column: {}", column_name))]
186 ConvertColumnDefaultConstraint {
187 column_name: String,
188 #[snafu(implicit)]
189 location: Location,
190 source: datatypes::error::Error,
191 },
192
193 #[snafu(display("Failed to convert datafusion schema"))]
194 ConvertSchema {
195 source: datatypes::error::Error,
196 #[snafu(implicit)]
197 location: Location,
198 },
199
200 #[snafu(display("Failed to convert expr to struct"))]
201 InvalidExpr {
202 #[snafu(implicit)]
203 location: Location,
204 source: common_meta::error::Error,
205 },
206
207 #[snafu(display("Invalid partition"))]
208 InvalidPartition {
209 #[snafu(implicit)]
210 location: Location,
211 source: partition::error::Error,
212 },
213
214 #[snafu(display("Invalid SQL, error: {}", err_msg))]
215 InvalidSql {
216 err_msg: String,
217 #[snafu(implicit)]
218 location: Location,
219 },
220
221 #[snafu(display("Invalid InsertRequest, reason: {}", reason))]
222 InvalidInsertRequest {
223 reason: String,
224 #[snafu(implicit)]
225 location: Location,
226 },
227
228 #[snafu(display("Invalid DeleteRequest, reason: {}", reason))]
229 InvalidDeleteRequest {
230 reason: String,
231 #[snafu(implicit)]
232 location: Location,
233 },
234
235 #[snafu(display("Invalid entity semantic option, reason: {}", reason))]
236 InvalidEntitySemanticOption {
237 reason: String,
238 #[snafu(implicit)]
239 location: Location,
240 },
241
242 #[snafu(display("Table not found: {}", table_name))]
243 TableNotFound { table_name: String },
244
245 #[snafu(display("Admin function not found: {}", name))]
246 AdminFunctionNotFound { name: String },
247
248 #[snafu(display("Flow not found: {}", flow_name))]
249 FlowNotFound { flow_name: String },
250
251 #[snafu(display("Failed to join task"))]
252 JoinTask {
253 #[snafu(source)]
254 error: common_runtime::JoinError,
255 #[snafu(implicit)]
256 location: Location,
257 },
258
259 #[snafu(display("General catalog error"))]
260 Catalog {
261 #[snafu(implicit)]
262 location: Location,
263 source: catalog::error::Error,
264 },
265
266 #[snafu(display("Failed to find view info for: {}", view_name))]
267 FindViewInfo {
268 view_name: String,
269 #[snafu(implicit)]
270 location: Location,
271 source: common_meta::error::Error,
272 },
273
274 #[snafu(display("View info not found: {}", view_name))]
275 ViewInfoNotFound {
276 view_name: String,
277 #[snafu(implicit)]
278 location: Location,
279 },
280
281 #[snafu(display("View not found: {}", view_name))]
282 ViewNotFound {
283 view_name: String,
284 #[snafu(implicit)]
285 location: Location,
286 },
287
288 #[snafu(display("Failed to find table partition rule for table {}", table_name))]
289 FindTablePartitionRule {
290 table_name: String,
291 #[snafu(implicit)]
292 location: Location,
293 source: partition::error::Error,
294 },
295
296 #[snafu(display("Failed to split insert request"))]
297 SplitInsert {
298 source: partition::error::Error,
299 #[snafu(implicit)]
300 location: Location,
301 },
302
303 #[snafu(display("Failed to split delete request"))]
304 SplitDelete {
305 source: partition::error::Error,
306 #[snafu(implicit)]
307 location: Location,
308 },
309
310 #[snafu(display("Failed to find leader for region"))]
311 FindRegionLeader {
312 source: partition::error::Error,
313 #[snafu(implicit)]
314 location: Location,
315 },
316
317 #[snafu(display("Failed to build CreateExpr on insertion"))]
318 BuildCreateExprOnInsertion {
319 #[snafu(implicit)]
320 location: Location,
321 source: common_grpc_expr::error::Error,
322 },
323
324 #[snafu(display("Failed to find schema, schema info: {}", schema_info))]
325 SchemaNotFound {
326 schema_info: String,
327 #[snafu(implicit)]
328 location: Location,
329 },
330
331 #[snafu(display("Schema {} already exists", name))]
332 SchemaExists {
333 name: String,
334 #[snafu(implicit)]
335 location: Location,
336 },
337
338 #[snafu(display("Schema `{name}` is in use"))]
339 SchemaInUse {
340 name: String,
341 #[snafu(implicit)]
342 location: Location,
343 },
344
345 #[snafu(display("Schema `{name}` is read-only"))]
346 SchemaReadOnly {
347 name: String,
348 #[snafu(implicit)]
349 location: Location,
350 },
351
352 #[snafu(display("Table `{name}` is read-only"))]
353 TableReadOnly {
354 name: String,
355 #[snafu(implicit)]
356 location: Location,
357 },
358
359 #[snafu(display(
360 "The definition of table `{name}` is managed by GreptimeDB; it cannot be created or altered (DROP recreates it on the next write)"
361 ))]
362 TableDdlReserved {
363 name: String,
364 #[snafu(implicit)]
365 location: Location,
366 },
367
368 #[snafu(display("Table occurs error"))]
369 Table {
370 #[snafu(implicit)]
371 location: Location,
372 source: table::error::Error,
373 },
374
375 #[snafu(display("Cannot find column by name: {}", msg))]
376 ColumnNotFound {
377 msg: String,
378 #[snafu(implicit)]
379 location: Location,
380 },
381
382 #[snafu(display("Failed to execute statement"))]
383 ExecuteStatement {
384 #[snafu(implicit)]
385 location: Location,
386 source: query::error::Error,
387 },
388
389 #[snafu(display("Failed to plan statement"))]
390 PlanStatement {
391 #[snafu(implicit)]
392 location: Location,
393 source: query::error::Error,
394 },
395
396 #[snafu(display("Failed to parse query"))]
397 ParseQuery {
398 #[snafu(implicit)]
399 location: Location,
400 source: query::error::Error,
401 },
402
403 #[snafu(display("Failed to execute logical plan"))]
404 ExecLogicalPlan {
405 #[snafu(implicit)]
406 location: Location,
407 source: query::error::Error,
408 },
409
410 #[snafu(display("Failed to build DataFusion logical plan"))]
411 BuildDfLogicalPlan {
412 #[snafu(source)]
413 error: datafusion_common::DataFusionError,
414 #[snafu(implicit)]
415 location: Location,
416 },
417
418 #[snafu(display("Failed to convert AlterExpr to AlterRequest"))]
419 AlterExprToRequest {
420 #[snafu(implicit)]
421 location: Location,
422 source: common_grpc_expr::error::Error,
423 },
424
425 #[snafu(display("Failed to build table meta for table: {}", table_name))]
426 BuildTableMeta {
427 table_name: String,
428 #[snafu(source)]
429 error: table::metadata::TableMetaBuilderError,
430 #[snafu(implicit)]
431 location: Location,
432 },
433
434 #[snafu(display("Not supported: {}", feat))]
435 NotSupported { feat: String },
436
437 #[snafu(display("Failed to find new columns on insertion"))]
438 FindNewColumnsOnInsertion {
439 #[snafu(implicit)]
440 location: Location,
441 source: common_grpc_expr::error::Error,
442 },
443
444 #[snafu(display("Failed to convert into vectors"))]
445 IntoVectors {
446 #[snafu(implicit)]
447 location: Location,
448 source: datatypes::error::Error,
449 },
450
451 #[snafu(display("Failed to describe schema for given statement"))]
452 DescribeStatement {
453 #[snafu(implicit)]
454 location: Location,
455 source: query::error::Error,
456 },
457
458 #[snafu(display("Illegal primary keys definition: {}", msg))]
459 IllegalPrimaryKeysDef {
460 msg: String,
461 #[snafu(implicit)]
462 location: Location,
463 },
464
465 #[snafu(display("Unrecognized table option"))]
466 UnrecognizedTableOption {
467 #[snafu(implicit)]
468 location: Location,
469 source: table::error::Error,
470 },
471
472 #[snafu(display("Missing time index column"))]
473 MissingTimeIndexColumn {
474 #[snafu(implicit)]
475 location: Location,
476 source: table::error::Error,
477 },
478
479 #[snafu(display("Failed to build regex"))]
480 BuildRegex {
481 #[snafu(implicit)]
482 location: Location,
483 #[snafu(source)]
484 error: regex::Error,
485 },
486
487 #[snafu(display("Failed to insert value into table: {}", table_name))]
488 Insert {
489 table_name: String,
490 #[snafu(implicit)]
491 location: Location,
492 source: table::error::Error,
493 },
494
495 #[snafu(display("Unsupported format: {:?}", format))]
496 UnsupportedFormat {
497 #[snafu(implicit)]
498 location: Location,
499 format: Format,
500 },
501
502 #[snafu(display("Failed to parse file format"))]
503 ParseFileFormat {
504 #[snafu(implicit)]
505 location: Location,
506 source: common_datasource::error::Error,
507 },
508
509 #[snafu(display("Failed to build data source backend"))]
510 BuildBackend {
511 #[snafu(implicit)]
512 location: Location,
513 source: common_datasource::error::Error,
514 },
515
516 #[snafu(display("Failed to list objects"))]
517 ListObjects {
518 #[snafu(implicit)]
519 location: Location,
520 source: common_datasource::error::Error,
521 },
522
523 #[snafu(display("Failed to infer schema from path: {}", path))]
524 InferSchema {
525 path: String,
526 #[snafu(implicit)]
527 location: Location,
528 source: common_datasource::error::Error,
529 },
530
531 #[snafu(display("Failed to write stream to path: {}", path))]
532 WriteStreamToFile {
533 path: String,
534 #[snafu(implicit)]
535 location: Location,
536 source: common_datasource::error::Error,
537 },
538
539 #[snafu(display("Failed to read object in path: {}", path))]
540 ReadObject {
541 path: String,
542 #[snafu(implicit)]
543 location: Location,
544 #[snafu(source)]
545 error: object_store::Error,
546 },
547
548 #[snafu(display("Failed to read record batch"))]
549 ReadDfRecordBatch {
550 #[snafu(source)]
551 error: datafusion::error::DataFusionError,
552 #[snafu(implicit)]
553 location: Location,
554 },
555
556 #[snafu(display("Failed to read parquet file metadata"))]
557 ReadParquetMetadata {
558 #[snafu(source)]
559 error: parquet::errors::ParquetError,
560 #[snafu(implicit)]
561 location: Location,
562 },
563
564 #[snafu(display("Failed to build record batch"))]
565 BuildRecordBatch {
566 #[snafu(implicit)]
567 location: Location,
568 source: common_recordbatch::error::Error,
569 },
570
571 #[snafu(display("Failed to read orc schema"))]
572 ReadOrc {
573 source: common_datasource::error::Error,
574 #[snafu(implicit)]
575 location: Location,
576 },
577
578 #[snafu(display("Failed to build parquet record batch stream"))]
579 BuildParquetRecordBatchStream {
580 #[snafu(implicit)]
581 location: Location,
582 #[snafu(source)]
583 error: parquet::errors::ParquetError,
584 },
585
586 #[snafu(display("Failed to build file stream"))]
587 BuildFileStream {
588 #[snafu(implicit)]
589 location: Location,
590 #[snafu(source)]
591 error: common_datasource::error::Error,
592 },
593
594 #[snafu(display(
595 "Schema datatypes not match at index {}, expected table schema: {}, actual file schema: {}",
596 index,
597 table_schema,
598 file_schema
599 ))]
600 InvalidSchema {
601 index: usize,
602 table_schema: String,
603 file_schema: String,
604 #[snafu(implicit)]
605 location: Location,
606 },
607
608 #[snafu(display(
609 "CSV header mismatch in path: {}, unknown columns: {:?}, missing columns: {:?}, duplicate columns: {:?}",
610 path,
611 unknown_columns,
612 missing_columns,
613 duplicate_columns
614 ))]
615 CsvHeaderMismatch {
616 path: String,
617 unknown_columns: Vec<String>,
618 missing_columns: Vec<String>,
619 duplicate_columns: Vec<String>,
620 #[snafu(implicit)]
621 location: Location,
622 },
623
624 #[snafu(display("Failed to project schema"))]
625 ProjectSchema {
626 #[snafu(source)]
627 error: ArrowError,
628 #[snafu(implicit)]
629 location: Location,
630 },
631
632 #[snafu(display("Failed to encode object into json"))]
633 EncodeJson {
634 #[snafu(source)]
635 error: serde_json::error::Error,
636 #[snafu(implicit)]
637 location: Location,
638 },
639
640 #[snafu(display("Invalid COPY parameter, key: {}, value: {}", key, value))]
641 InvalidCopyParameter {
642 key: String,
643 value: String,
644 #[snafu(implicit)]
645 location: Location,
646 },
647
648 #[snafu(display("Invalid COPY DATABASE location, must end with '/': {}", value))]
649 InvalidCopyDatabasePath {
650 value: String,
651 #[snafu(implicit)]
652 location: Location,
653 },
654
655 #[snafu(display("Table metadata manager error"))]
656 TableMetadataManager {
657 source: common_meta::error::Error,
658 #[snafu(implicit)]
659 location: Location,
660 },
661
662 #[snafu(display("Missing insert body"))]
663 MissingInsertBody {
664 source: sql::error::Error,
665 #[snafu(implicit)]
666 location: Location,
667 },
668
669 #[snafu(display("Failed to parse sql value"))]
670 ParseSqlValue {
671 source: sql::error::Error,
672 #[snafu(implicit)]
673 location: Location,
674 },
675
676 #[snafu(display("Failed to build default value, column: {}", column))]
677 ColumnDefaultValue {
678 column: String,
679 #[snafu(implicit)]
680 location: Location,
681 source: datatypes::error::Error,
682 },
683
684 #[snafu(display(
685 "No valid default value can be built automatically, column: {}",
686 column,
687 ))]
688 ColumnNoneDefaultValue {
689 column: String,
690 #[snafu(implicit)]
691 location: Location,
692 },
693
694 #[snafu(display("Failed to prepare file table"))]
695 PrepareFileTable {
696 #[snafu(implicit)]
697 location: Location,
698 source: query::error::Error,
699 },
700
701 #[snafu(display("Failed to infer file table schema"))]
702 InferFileTableSchema {
703 #[snafu(implicit)]
704 location: Location,
705 source: query::error::Error,
706 },
707
708 #[snafu(display("The schema of the file table is incompatible with the table schema"))]
709 SchemaIncompatible {
710 #[snafu(implicit)]
711 location: Location,
712 source: query::error::Error,
713 },
714
715 #[snafu(display("Invalid table name: {}", table_name))]
716 InvalidTableName {
717 table_name: String,
718 #[snafu(implicit)]
719 location: Location,
720 },
721
722 #[snafu(display("Invalid view name: {name}"))]
723 InvalidViewName {
724 name: String,
725 #[snafu(implicit)]
726 location: Location,
727 },
728
729 #[snafu(display("Invalid flow name: {name}"))]
730 InvalidFlowName {
731 name: String,
732 #[snafu(implicit)]
733 location: Location,
734 },
735
736 #[cfg(feature = "enterprise")]
737 #[snafu(display("Invalid trigger name: {name}"))]
738 InvalidTriggerName {
739 name: String,
740 #[snafu(implicit)]
741 location: Location,
742 },
743
744 #[snafu(display("Empty {} expr", name))]
745 EmptyDdlExpr {
746 name: String,
747 #[snafu(implicit)]
748 location: Location,
749 },
750
751 #[snafu(display("Failed to create logical tables: {}", reason))]
752 CreateLogicalTables {
753 reason: String,
754 #[snafu(implicit)]
755 location: Location,
756 },
757
758 #[snafu(display("Invalid partition rule: {}", reason))]
759 InvalidPartitionRule {
760 reason: String,
761 #[snafu(implicit)]
762 location: Location,
763 },
764
765 #[snafu(display("Failed to serialize partition expression"))]
766 SerializePartitionExpr {
767 #[snafu(implicit)]
768 location: Location,
769 source: partition::error::Error,
770 },
771
772 #[snafu(display("Failed to deserialize partition expression"))]
773 DeserializePartitionExpr {
774 #[snafu(source)]
775 source: partition::error::Error,
776 #[snafu(implicit)]
777 location: Location,
778 },
779
780 #[snafu(display("Invalid configuration value."))]
781 InvalidConfigValue {
782 source: session::session_config::Error,
783 #[snafu(implicit)]
784 location: Location,
785 },
786
787 #[snafu(display("Invalid timestamp range, start: `{}`, end: `{}`", start, end))]
788 InvalidTimestampRange {
789 start: String,
790 end: String,
791 #[snafu(implicit)]
792 location: Location,
793 },
794
795 #[snafu(display("Failed to convert between logical plan and substrait plan"))]
796 SubstraitCodec {
797 #[snafu(implicit)]
798 location: Location,
799 source: substrait::error::Error,
800 },
801
802 #[snafu(display(
803 "Show create table only for base table. {} is {}",
804 table_name,
805 table_type
806 ))]
807 ShowCreateTableBaseOnly {
808 table_name: String,
809 table_type: TableType,
810 #[snafu(implicit)]
811 location: Location,
812 },
813 #[snafu(display("Create physical expr error"))]
814 PhysicalExpr {
815 #[snafu(source)]
816 error: common_recordbatch::error::Error,
817 #[snafu(implicit)]
818 location: Location,
819 },
820
821 #[snafu(display("Failed to upgrade catalog manager reference"))]
822 UpgradeCatalogManagerRef {
823 #[snafu(implicit)]
824 location: Location,
825 },
826
827 #[snafu(display("Invalid json text: {}", json))]
828 InvalidJsonFormat {
829 #[snafu(implicit)]
830 location: Location,
831 json: String,
832 },
833
834 #[snafu(display("Cursor {name} is not found"))]
835 CursorNotFound { name: String },
836
837 #[snafu(display("A cursor named {name} already exists"))]
838 CursorExists { name: String },
839
840 #[snafu(display("Column options error"))]
841 ColumnOptions {
842 #[snafu(source)]
843 source: api::error::Error,
844 #[snafu(implicit)]
845 location: Location,
846 },
847
848 #[snafu(display("Failed to create partition rules"))]
849 CreatePartitionRules {
850 #[snafu(source)]
851 source: sql::error::Error,
852 #[snafu(implicit)]
853 location: Location,
854 },
855
856 #[snafu(display("Failed to decode arrow flight data"))]
857 DecodeFlightData {
858 source: common_grpc::error::Error,
859 #[snafu(implicit)]
860 location: Location,
861 },
862
863 #[snafu(display("Failed to perform arrow compute"))]
864 ComputeArrow {
865 #[snafu(source)]
866 error: ArrowError,
867 #[snafu(implicit)]
868 location: Location,
869 },
870
871 #[snafu(display("Invalid time index type: {}", ty))]
872 InvalidTimeIndexType {
873 ty: arrow::datatypes::DataType,
874 #[snafu(implicit)]
875 location: Location,
876 },
877
878 #[snafu(display("Invalid timezone: {}", timezone))]
879 InvalidTimezone {
880 timezone: String,
881 #[snafu(source)]
882 source: common_time::error::Error,
883 #[snafu(implicit)]
884 location: Location,
885 },
886
887 #[snafu(display("Invalid process id: {}", id))]
888 InvalidProcessId { id: String },
889
890 #[snafu(display("ProcessManager is not present, this can be caused by misconfiguration."))]
891 ProcessManagerMissing {
892 #[snafu(implicit)]
893 location: Location,
894 },
895
896 #[snafu(display("Sql common error"))]
897 SqlCommon {
898 source: common_sql::error::Error,
899 #[snafu(implicit)]
900 location: Location,
901 },
902
903 #[snafu(display("Failed to convert partition expression to protobuf"))]
904 PartitionExprToPb {
905 source: partition::error::Error,
906 #[snafu(implicit)]
907 location: Location,
908 },
909
910 #[snafu(display(
911 "{} not supported when transforming to {} format type",
912 format,
913 file_format
914 ))]
915 TimestampFormatNotSupported {
916 file_format: String,
917 format: String,
918 #[snafu(implicit)]
919 location: Location,
920 },
921
922 #[cfg(feature = "enterprise")]
923 #[snafu(display("Too large duration"))]
924 TooLargeDuration {
925 #[snafu(source)]
926 error: prost_types::DurationError,
927 #[snafu(implicit)]
928 location: Location,
929 },
930
931 #[cfg(feature = "enterprise")]
932 #[snafu(display("Not trigger querier is specified"))]
933 MissingTriggerQuerier {
934 #[snafu(implicit)]
935 location: Location,
936 },
937
938 #[cfg(feature = "enterprise")]
939 #[snafu(display("Trigger querier error"))]
940 TriggerQuerier {
941 source: BoxedError,
942 #[snafu(implicit)]
943 location: Location,
944 },
945}
946
947pub type Result<T> = std::result::Result<T, Error>;
948
949impl ErrorExt for Error {
950 fn status_code(&self) -> StatusCode {
951 match self {
952 Error::Cast { source, .. } => source.status_code(),
953 Error::InvalidSql { .. }
954 | Error::InvalidConfigValue { .. }
955 | Error::InvalidInsertRequest { .. }
956 | Error::InvalidDeleteRequest { .. }
957 | Error::InvalidEntitySemanticOption { .. }
958 | Error::IllegalPrimaryKeysDef { .. }
959 | Error::SchemaNotFound { .. }
960 | Error::SchemaExists { .. }
961 | Error::SchemaInUse { .. }
962 | Error::ColumnNotFound { .. }
963 | Error::BuildRegex { .. }
964 | Error::InvalidSchema { .. }
965 | Error::CsvHeaderMismatch { .. }
966 | Error::ProjectSchema { .. }
967 | Error::UnsupportedFormat { .. }
968 | Error::ColumnNoneDefaultValue { .. }
969 | Error::PrepareFileTable { .. }
970 | Error::InferFileTableSchema { .. }
971 | Error::SchemaIncompatible { .. }
972 | Error::ConvertSchema { .. }
973 | Error::UnsupportedRegionRequest { .. }
974 | Error::InvalidTableName { .. }
975 | Error::InvalidViewName { .. }
976 | Error::InvalidFlowName { .. }
977 | Error::InvalidView { .. }
978 | Error::InvalidExpr { .. }
979 | Error::AdminFunctionNotFound { .. }
980 | Error::ViewColumnsMismatch { .. }
981 | Error::InvalidViewStmt { .. }
982 | Error::ConvertIdentifier { .. }
983 | Error::BuildAdminFunctionArgs { .. }
984 | Error::FunctionArityMismatch { .. }
985 | Error::InvalidPartition { .. }
986 | Error::PhysicalExpr { .. }
987 | Error::InvalidJsonFormat { .. }
988 | Error::PartitionExprToPb { .. }
989 | Error::CursorNotFound { .. }
990 | Error::CursorExists { .. }
991 | Error::CreatePartitionRules { .. } => StatusCode::InvalidArguments,
992 Error::TableAlreadyExists { .. } | Error::ViewAlreadyExists { .. } => {
993 StatusCode::TableAlreadyExists
994 }
995 Error::NotSupported { .. }
996 | Error::ShowCreateTableBaseOnly { .. }
997 | Error::SchemaReadOnly { .. }
998 | Error::TableReadOnly { .. }
999 | Error::TableDdlReserved { .. } => StatusCode::Unsupported,
1000 Error::TableMetadataManager { source, .. } => source.status_code(),
1001 Error::ParseSql { source, .. } => source.status_code(),
1002 Error::InvalidateTableCache { source, .. } => source.status_code(),
1003 Error::ParseFileFormat { source, .. } | Error::InferSchema { source, .. } => {
1004 source.status_code()
1005 }
1006 Error::Table { source, .. } | Error::Insert { source, .. } => source.status_code(),
1007 Error::ConvertColumnDefaultConstraint { source, .. }
1008 | Error::IntoVectors { source, .. } => source.status_code(),
1009 Error::RequestInserts { source, .. } | Error::FindViewInfo { source, .. } => {
1010 source.status_code()
1011 }
1012 Error::RequestRegion { source, .. } => source.status_code(),
1013 Error::RequestDeletes { source, .. } => source.status_code(),
1014 Error::SubstraitCodec { source, .. } => source.status_code(),
1015 Error::ColumnDataType { source, .. } | Error::InvalidColumnDef { source, .. } => {
1016 source.status_code()
1017 }
1018 Error::MissingTimeIndexColumn { source, .. } => source.status_code(),
1019 Error::BuildDfLogicalPlan { .. }
1020 | Error::BuildTableMeta { .. }
1021 | Error::MissingInsertBody { .. } => StatusCode::Internal,
1022 Error::ExecuteAdminFunction { .. }
1023 | Error::EncodeJson { .. }
1024 | Error::DeserializePartitionExpr { .. }
1025 | Error::SerializePartitionExpr { .. } => StatusCode::Unexpected,
1026 Error::ViewNotFound { .. }
1027 | Error::ViewInfoNotFound { .. }
1028 | Error::TableNotFound { .. } => StatusCode::TableNotFound,
1029 Error::FlowNotFound { .. } => StatusCode::FlowNotFound,
1030 Error::JoinTask { .. } => StatusCode::Internal,
1031 Error::BuildParquetRecordBatchStream { .. }
1032 | Error::BuildFileStream { .. }
1033 | Error::WriteStreamToFile { .. }
1034 | Error::ReadDfRecordBatch { .. }
1035 | Error::Unexpected { .. } => StatusCode::Unexpected,
1036 Error::Catalog { source, .. } => source.status_code(),
1037 Error::BuildCreateExprOnInsertion { source, .. }
1038 | Error::FindNewColumnsOnInsertion { source, .. } => source.status_code(),
1039 Error::ExecuteStatement { source, .. }
1040 | Error::ExtractTableNames { source, .. }
1041 | Error::PlanStatement { source, .. }
1042 | Error::ParseQuery { source, .. }
1043 | Error::ExecLogicalPlan { source, .. }
1044 | Error::DescribeStatement { source, .. } => source.status_code(),
1045 Error::AlterExprToRequest { source, .. } => source.status_code(),
1046 Error::External { source, .. } => source.status_code(),
1047 Error::FindTablePartitionRule { source, .. }
1048 | Error::SplitInsert { source, .. }
1049 | Error::SplitDelete { source, .. }
1050 | Error::FindRegionLeader { source, .. } => source.status_code(),
1051 Error::UnrecognizedTableOption { .. } => StatusCode::InvalidArguments,
1052 Error::ReadObject { .. }
1053 | Error::ReadParquetMetadata { .. }
1054 | Error::ReadOrc { .. } => StatusCode::StorageUnavailable,
1055 Error::ListObjects { source, .. } | Error::BuildBackend { source, .. } => {
1056 source.status_code()
1057 }
1058 Error::ExecuteDdl { source, .. } => source.status_code(),
1059 Error::InvalidCopyParameter { .. } | Error::InvalidCopyDatabasePath { .. } => {
1060 StatusCode::InvalidArguments
1061 }
1062 Error::ColumnDefaultValue { source, .. } => source.status_code(),
1063 Error::EmptyDdlExpr { .. }
1064 | Error::InvalidPartitionRule { .. }
1065 | Error::ParseSqlValue { .. }
1066 | Error::InvalidTimestampRange { .. } => StatusCode::InvalidArguments,
1067 Error::CreateLogicalTables { .. } => StatusCode::Unexpected,
1068 Error::BuildRecordBatch { source, .. } => source.status_code(),
1069 Error::UpgradeCatalogManagerRef { .. } => StatusCode::Internal,
1070 Error::ColumnOptions { source, .. } => source.status_code(),
1071 Error::DecodeFlightData { source, .. } => source.status_code(),
1072 Error::ComputeArrow { .. } => StatusCode::Internal,
1073 Error::InvalidTimeIndexType { .. } | Error::InvalidTimezone { .. } => {
1074 StatusCode::InvalidArguments
1075 }
1076 Error::InvalidProcessId { .. } => StatusCode::InvalidArguments,
1077 Error::ProcessManagerMissing { .. } => StatusCode::Unexpected,
1078 Error::TimestampFormatNotSupported { .. } => StatusCode::InvalidArguments,
1079 Error::SqlCommon { source, .. } => source.status_code(),
1080 #[cfg(feature = "enterprise")]
1081 Error::InvalidTriggerName { .. } => StatusCode::InvalidArguments,
1082 #[cfg(feature = "enterprise")]
1083 Error::TooLargeDuration { .. } => StatusCode::InvalidArguments,
1084 #[cfg(feature = "enterprise")]
1085 Error::MissingTriggerQuerier { .. } => StatusCode::Internal,
1086 #[cfg(feature = "enterprise")]
1087 Error::TriggerQuerier { source, .. } => source.status_code(),
1088 }
1089 }
1090
1091 fn as_any(&self) -> &dyn Any {
1092 self
1093 }
1094
1095 fn retry_hint(&self) -> RetryHint {
1096 match self {
1097 Error::ReadObject { error, .. } => retry_hint_from_opendal_error(error),
1098 Error::ReadParquetMetadata { .. } => RetryHint::Retryable,
1099 Error::InvalidateTableCache { source, .. }
1100 | Error::ExecuteDdl { source, .. }
1101 | Error::RequestInserts { source, .. }
1102 | Error::RequestDeletes { source, .. }
1103 | Error::RequestRegion { source, .. }
1104 | Error::FindViewInfo { source, .. }
1105 | Error::TableMetadataManager { source, .. } => source.retry_hint(),
1106
1107 Error::ParseFileFormat { source, .. }
1108 | Error::InferSchema { source, .. }
1109 | Error::ListObjects { source, .. }
1110 | Error::BuildBackend { source, .. }
1111 | Error::ReadOrc { source, .. } => source.retry_hint(),
1112
1113 Error::ExtractTableNames { source, .. }
1114 | Error::ExecuteStatement { source, .. }
1115 | Error::PlanStatement { source, .. }
1116 | Error::ParseQuery { source, .. }
1117 | Error::ExecLogicalPlan { source, .. }
1118 | Error::DescribeStatement { source, .. } => source.retry_hint(),
1119
1120 Error::FindTablePartitionRule { source, .. }
1121 | Error::SplitInsert { source, .. }
1122 | Error::SplitDelete { source, .. }
1123 | Error::FindRegionLeader { source, .. } => source.retry_hint(),
1124
1125 Error::BuildCreateExprOnInsertion { source, .. }
1126 | Error::FindNewColumnsOnInsertion { source, .. }
1127 | Error::AlterExprToRequest { source, .. } => source.retry_hint(),
1128
1129 Error::ConvertColumnDefaultConstraint { source, .. }
1130 | Error::IntoVectors { source, .. }
1131 | Error::ColumnDefaultValue { source, .. } => source.retry_hint(),
1132
1133 Error::ColumnDataType { source, .. }
1134 | Error::InvalidColumnDef { source, .. }
1135 | Error::ColumnOptions { source, .. } => source.retry_hint(),
1136
1137 Error::Table { source, .. }
1138 | Error::Insert { source, .. }
1139 | Error::MissingTimeIndexColumn { source, .. } => source.retry_hint(),
1140
1141 Error::Cast { source, .. } => source.retry_hint(),
1142 Error::ParseSql { source, .. } => source.retry_hint(),
1143 Error::Catalog { source, .. } => source.retry_hint(),
1144 Error::SubstraitCodec { source, .. } => source.retry_hint(),
1145 Error::External { source, .. } => source.retry_hint(),
1146 Error::BuildRecordBatch { source, .. } => source.retry_hint(),
1147 Error::DecodeFlightData { source, .. } => source.retry_hint(),
1148 Error::SqlCommon { source, .. } => source.retry_hint(),
1149 Error::ConvertSchema { source, .. } => source.retry_hint(),
1150 Error::WriteStreamToFile { source, .. } => source.retry_hint(),
1151 Error::PrepareFileTable { source, .. } | Error::InferFileTableSchema { source, .. } => {
1152 source.retry_hint()
1153 }
1154 #[cfg(feature = "enterprise")]
1155 Error::TriggerQuerier { source, .. } => source.retry_hint(),
1156 _ => RetryHint::NonRetryable,
1157 }
1158 }
1159}
1160
1161define_into_tonic_status!(Error);