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