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("Table occurs error"))]
360 Table {
361 #[snafu(implicit)]
362 location: Location,
363 source: table::error::Error,
364 },
365
366 #[snafu(display("Cannot find column by name: {}", msg))]
367 ColumnNotFound {
368 msg: String,
369 #[snafu(implicit)]
370 location: Location,
371 },
372
373 #[snafu(display("Failed to execute statement"))]
374 ExecuteStatement {
375 #[snafu(implicit)]
376 location: Location,
377 source: query::error::Error,
378 },
379
380 #[snafu(display("Failed to plan statement"))]
381 PlanStatement {
382 #[snafu(implicit)]
383 location: Location,
384 source: query::error::Error,
385 },
386
387 #[snafu(display("Failed to parse query"))]
388 ParseQuery {
389 #[snafu(implicit)]
390 location: Location,
391 source: query::error::Error,
392 },
393
394 #[snafu(display("Failed to execute logical plan"))]
395 ExecLogicalPlan {
396 #[snafu(implicit)]
397 location: Location,
398 source: query::error::Error,
399 },
400
401 #[snafu(display("Failed to build DataFusion logical plan"))]
402 BuildDfLogicalPlan {
403 #[snafu(source)]
404 error: datafusion_common::DataFusionError,
405 #[snafu(implicit)]
406 location: Location,
407 },
408
409 #[snafu(display("Failed to convert AlterExpr to AlterRequest"))]
410 AlterExprToRequest {
411 #[snafu(implicit)]
412 location: Location,
413 source: common_grpc_expr::error::Error,
414 },
415
416 #[snafu(display("Failed to build table meta for table: {}", table_name))]
417 BuildTableMeta {
418 table_name: String,
419 #[snafu(source)]
420 error: table::metadata::TableMetaBuilderError,
421 #[snafu(implicit)]
422 location: Location,
423 },
424
425 #[snafu(display("Not supported: {}", feat))]
426 NotSupported { feat: String },
427
428 #[snafu(display("Failed to find new columns on insertion"))]
429 FindNewColumnsOnInsertion {
430 #[snafu(implicit)]
431 location: Location,
432 source: common_grpc_expr::error::Error,
433 },
434
435 #[snafu(display("Failed to convert into vectors"))]
436 IntoVectors {
437 #[snafu(implicit)]
438 location: Location,
439 source: datatypes::error::Error,
440 },
441
442 #[snafu(display("Failed to describe schema for given statement"))]
443 DescribeStatement {
444 #[snafu(implicit)]
445 location: Location,
446 source: query::error::Error,
447 },
448
449 #[snafu(display("Illegal primary keys definition: {}", msg))]
450 IllegalPrimaryKeysDef {
451 msg: String,
452 #[snafu(implicit)]
453 location: Location,
454 },
455
456 #[snafu(display("Unrecognized table option"))]
457 UnrecognizedTableOption {
458 #[snafu(implicit)]
459 location: Location,
460 source: table::error::Error,
461 },
462
463 #[snafu(display("Missing time index column"))]
464 MissingTimeIndexColumn {
465 #[snafu(implicit)]
466 location: Location,
467 source: table::error::Error,
468 },
469
470 #[snafu(display("Failed to build regex"))]
471 BuildRegex {
472 #[snafu(implicit)]
473 location: Location,
474 #[snafu(source)]
475 error: regex::Error,
476 },
477
478 #[snafu(display("Failed to insert value into table: {}", table_name))]
479 Insert {
480 table_name: String,
481 #[snafu(implicit)]
482 location: Location,
483 source: table::error::Error,
484 },
485
486 #[snafu(display("Unsupported format: {:?}", format))]
487 UnsupportedFormat {
488 #[snafu(implicit)]
489 location: Location,
490 format: Format,
491 },
492
493 #[snafu(display("Failed to parse file format"))]
494 ParseFileFormat {
495 #[snafu(implicit)]
496 location: Location,
497 source: common_datasource::error::Error,
498 },
499
500 #[snafu(display("Failed to build data source backend"))]
501 BuildBackend {
502 #[snafu(implicit)]
503 location: Location,
504 source: common_datasource::error::Error,
505 },
506
507 #[snafu(display("Failed to list objects"))]
508 ListObjects {
509 #[snafu(implicit)]
510 location: Location,
511 source: common_datasource::error::Error,
512 },
513
514 #[snafu(display("Failed to infer schema from path: {}", path))]
515 InferSchema {
516 path: String,
517 #[snafu(implicit)]
518 location: Location,
519 source: common_datasource::error::Error,
520 },
521
522 #[snafu(display("Failed to write stream to path: {}", path))]
523 WriteStreamToFile {
524 path: String,
525 #[snafu(implicit)]
526 location: Location,
527 source: common_datasource::error::Error,
528 },
529
530 #[snafu(display("Failed to read object in path: {}", path))]
531 ReadObject {
532 path: String,
533 #[snafu(implicit)]
534 location: Location,
535 #[snafu(source)]
536 error: object_store::Error,
537 },
538
539 #[snafu(display("Failed to read record batch"))]
540 ReadDfRecordBatch {
541 #[snafu(source)]
542 error: datafusion::error::DataFusionError,
543 #[snafu(implicit)]
544 location: Location,
545 },
546
547 #[snafu(display("Failed to read parquet file metadata"))]
548 ReadParquetMetadata {
549 #[snafu(source)]
550 error: parquet::errors::ParquetError,
551 #[snafu(implicit)]
552 location: Location,
553 },
554
555 #[snafu(display("Failed to build record batch"))]
556 BuildRecordBatch {
557 #[snafu(implicit)]
558 location: Location,
559 source: common_recordbatch::error::Error,
560 },
561
562 #[snafu(display("Failed to read orc schema"))]
563 ReadOrc {
564 source: common_datasource::error::Error,
565 #[snafu(implicit)]
566 location: Location,
567 },
568
569 #[snafu(display("Failed to build parquet record batch stream"))]
570 BuildParquetRecordBatchStream {
571 #[snafu(implicit)]
572 location: Location,
573 #[snafu(source)]
574 error: parquet::errors::ParquetError,
575 },
576
577 #[snafu(display("Failed to build file stream"))]
578 BuildFileStream {
579 #[snafu(implicit)]
580 location: Location,
581 #[snafu(source)]
582 error: common_datasource::error::Error,
583 },
584
585 #[snafu(display(
586 "Schema datatypes not match at index {}, expected table schema: {}, actual file schema: {}",
587 index,
588 table_schema,
589 file_schema
590 ))]
591 InvalidSchema {
592 index: usize,
593 table_schema: String,
594 file_schema: String,
595 #[snafu(implicit)]
596 location: Location,
597 },
598
599 #[snafu(display(
600 "CSV header mismatch in path: {}, unknown columns: {:?}, missing columns: {:?}, duplicate columns: {:?}",
601 path,
602 unknown_columns,
603 missing_columns,
604 duplicate_columns
605 ))]
606 CsvHeaderMismatch {
607 path: String,
608 unknown_columns: Vec<String>,
609 missing_columns: Vec<String>,
610 duplicate_columns: Vec<String>,
611 #[snafu(implicit)]
612 location: Location,
613 },
614
615 #[snafu(display("Failed to project schema"))]
616 ProjectSchema {
617 #[snafu(source)]
618 error: ArrowError,
619 #[snafu(implicit)]
620 location: Location,
621 },
622
623 #[snafu(display("Failed to encode object into json"))]
624 EncodeJson {
625 #[snafu(source)]
626 error: serde_json::error::Error,
627 #[snafu(implicit)]
628 location: Location,
629 },
630
631 #[snafu(display("Invalid COPY parameter, key: {}, value: {}", key, value))]
632 InvalidCopyParameter {
633 key: String,
634 value: String,
635 #[snafu(implicit)]
636 location: Location,
637 },
638
639 #[snafu(display("Invalid COPY DATABASE location, must end with '/': {}", value))]
640 InvalidCopyDatabasePath {
641 value: String,
642 #[snafu(implicit)]
643 location: Location,
644 },
645
646 #[snafu(display("Table metadata manager error"))]
647 TableMetadataManager {
648 source: common_meta::error::Error,
649 #[snafu(implicit)]
650 location: Location,
651 },
652
653 #[snafu(display("Missing insert body"))]
654 MissingInsertBody {
655 source: sql::error::Error,
656 #[snafu(implicit)]
657 location: Location,
658 },
659
660 #[snafu(display("Failed to parse sql value"))]
661 ParseSqlValue {
662 source: sql::error::Error,
663 #[snafu(implicit)]
664 location: Location,
665 },
666
667 #[snafu(display("Failed to build default value, column: {}", column))]
668 ColumnDefaultValue {
669 column: String,
670 #[snafu(implicit)]
671 location: Location,
672 source: datatypes::error::Error,
673 },
674
675 #[snafu(display(
676 "No valid default value can be built automatically, column: {}",
677 column,
678 ))]
679 ColumnNoneDefaultValue {
680 column: String,
681 #[snafu(implicit)]
682 location: Location,
683 },
684
685 #[snafu(display("Failed to prepare file table"))]
686 PrepareFileTable {
687 #[snafu(implicit)]
688 location: Location,
689 source: query::error::Error,
690 },
691
692 #[snafu(display("Failed to infer file table schema"))]
693 InferFileTableSchema {
694 #[snafu(implicit)]
695 location: Location,
696 source: query::error::Error,
697 },
698
699 #[snafu(display("The schema of the file table is incompatible with the table schema"))]
700 SchemaIncompatible {
701 #[snafu(implicit)]
702 location: Location,
703 source: query::error::Error,
704 },
705
706 #[snafu(display("Invalid table name: {}", table_name))]
707 InvalidTableName {
708 table_name: String,
709 #[snafu(implicit)]
710 location: Location,
711 },
712
713 #[snafu(display("Invalid view name: {name}"))]
714 InvalidViewName {
715 name: String,
716 #[snafu(implicit)]
717 location: Location,
718 },
719
720 #[snafu(display("Invalid flow name: {name}"))]
721 InvalidFlowName {
722 name: String,
723 #[snafu(implicit)]
724 location: Location,
725 },
726
727 #[cfg(feature = "enterprise")]
728 #[snafu(display("Invalid trigger name: {name}"))]
729 InvalidTriggerName {
730 name: String,
731 #[snafu(implicit)]
732 location: Location,
733 },
734
735 #[snafu(display("Empty {} expr", name))]
736 EmptyDdlExpr {
737 name: String,
738 #[snafu(implicit)]
739 location: Location,
740 },
741
742 #[snafu(display("Failed to create logical tables: {}", reason))]
743 CreateLogicalTables {
744 reason: String,
745 #[snafu(implicit)]
746 location: Location,
747 },
748
749 #[snafu(display("Invalid partition rule: {}", reason))]
750 InvalidPartitionRule {
751 reason: String,
752 #[snafu(implicit)]
753 location: Location,
754 },
755
756 #[snafu(display("Failed to serialize partition expression"))]
757 SerializePartitionExpr {
758 #[snafu(implicit)]
759 location: Location,
760 source: partition::error::Error,
761 },
762
763 #[snafu(display("Failed to deserialize partition expression"))]
764 DeserializePartitionExpr {
765 #[snafu(source)]
766 source: partition::error::Error,
767 #[snafu(implicit)]
768 location: Location,
769 },
770
771 #[snafu(display("Invalid configuration value."))]
772 InvalidConfigValue {
773 source: session::session_config::Error,
774 #[snafu(implicit)]
775 location: Location,
776 },
777
778 #[snafu(display("Invalid timestamp range, start: `{}`, end: `{}`", start, end))]
779 InvalidTimestampRange {
780 start: String,
781 end: String,
782 #[snafu(implicit)]
783 location: Location,
784 },
785
786 #[snafu(display("Failed to convert between logical plan and substrait plan"))]
787 SubstraitCodec {
788 #[snafu(implicit)]
789 location: Location,
790 source: substrait::error::Error,
791 },
792
793 #[snafu(display(
794 "Show create table only for base table. {} is {}",
795 table_name,
796 table_type
797 ))]
798 ShowCreateTableBaseOnly {
799 table_name: String,
800 table_type: TableType,
801 #[snafu(implicit)]
802 location: Location,
803 },
804 #[snafu(display("Create physical expr error"))]
805 PhysicalExpr {
806 #[snafu(source)]
807 error: common_recordbatch::error::Error,
808 #[snafu(implicit)]
809 location: Location,
810 },
811
812 #[snafu(display("Failed to upgrade catalog manager reference"))]
813 UpgradeCatalogManagerRef {
814 #[snafu(implicit)]
815 location: Location,
816 },
817
818 #[snafu(display("Invalid json text: {}", json))]
819 InvalidJsonFormat {
820 #[snafu(implicit)]
821 location: Location,
822 json: String,
823 },
824
825 #[snafu(display("Cursor {name} is not found"))]
826 CursorNotFound { name: String },
827
828 #[snafu(display("A cursor named {name} already exists"))]
829 CursorExists { name: String },
830
831 #[snafu(display("Column options error"))]
832 ColumnOptions {
833 #[snafu(source)]
834 source: api::error::Error,
835 #[snafu(implicit)]
836 location: Location,
837 },
838
839 #[snafu(display("Failed to create partition rules"))]
840 CreatePartitionRules {
841 #[snafu(source)]
842 source: sql::error::Error,
843 #[snafu(implicit)]
844 location: Location,
845 },
846
847 #[snafu(display("Failed to decode arrow flight data"))]
848 DecodeFlightData {
849 source: common_grpc::error::Error,
850 #[snafu(implicit)]
851 location: Location,
852 },
853
854 #[snafu(display("Failed to perform arrow compute"))]
855 ComputeArrow {
856 #[snafu(source)]
857 error: ArrowError,
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::InvalidEntitySemanticOption { .. }
949 | Error::IllegalPrimaryKeysDef { .. }
950 | Error::SchemaNotFound { .. }
951 | Error::SchemaExists { .. }
952 | Error::SchemaInUse { .. }
953 | Error::ColumnNotFound { .. }
954 | Error::BuildRegex { .. }
955 | Error::InvalidSchema { .. }
956 | Error::CsvHeaderMismatch { .. }
957 | Error::ProjectSchema { .. }
958 | Error::UnsupportedFormat { .. }
959 | Error::ColumnNoneDefaultValue { .. }
960 | Error::PrepareFileTable { .. }
961 | Error::InferFileTableSchema { .. }
962 | Error::SchemaIncompatible { .. }
963 | Error::ConvertSchema { .. }
964 | Error::UnsupportedRegionRequest { .. }
965 | Error::InvalidTableName { .. }
966 | Error::InvalidViewName { .. }
967 | Error::InvalidFlowName { .. }
968 | Error::InvalidView { .. }
969 | Error::InvalidExpr { .. }
970 | Error::AdminFunctionNotFound { .. }
971 | Error::ViewColumnsMismatch { .. }
972 | Error::InvalidViewStmt { .. }
973 | Error::ConvertIdentifier { .. }
974 | Error::BuildAdminFunctionArgs { .. }
975 | Error::FunctionArityMismatch { .. }
976 | Error::InvalidPartition { .. }
977 | Error::PhysicalExpr { .. }
978 | Error::InvalidJsonFormat { .. }
979 | Error::PartitionExprToPb { .. }
980 | Error::CursorNotFound { .. }
981 | Error::CursorExists { .. }
982 | Error::CreatePartitionRules { .. } => StatusCode::InvalidArguments,
983 Error::TableAlreadyExists { .. } | Error::ViewAlreadyExists { .. } => {
984 StatusCode::TableAlreadyExists
985 }
986 Error::NotSupported { .. }
987 | Error::ShowCreateTableBaseOnly { .. }
988 | Error::SchemaReadOnly { .. }
989 | Error::TableReadOnly { .. } => StatusCode::Unsupported,
990 Error::TableMetadataManager { source, .. } => source.status_code(),
991 Error::ParseSql { source, .. } => source.status_code(),
992 Error::InvalidateTableCache { source, .. } => source.status_code(),
993 Error::ParseFileFormat { source, .. } | Error::InferSchema { source, .. } => {
994 source.status_code()
995 }
996 Error::Table { source, .. } | Error::Insert { source, .. } => source.status_code(),
997 Error::ConvertColumnDefaultConstraint { source, .. }
998 | Error::IntoVectors { source, .. } => source.status_code(),
999 Error::RequestInserts { source, .. } | Error::FindViewInfo { source, .. } => {
1000 source.status_code()
1001 }
1002 Error::RequestRegion { source, .. } => source.status_code(),
1003 Error::RequestDeletes { source, .. } => source.status_code(),
1004 Error::SubstraitCodec { source, .. } => source.status_code(),
1005 Error::ColumnDataType { source, .. } | Error::InvalidColumnDef { source, .. } => {
1006 source.status_code()
1007 }
1008 Error::MissingTimeIndexColumn { source, .. } => source.status_code(),
1009 Error::BuildDfLogicalPlan { .. }
1010 | Error::BuildTableMeta { .. }
1011 | Error::MissingInsertBody { .. } => StatusCode::Internal,
1012 Error::ExecuteAdminFunction { .. }
1013 | Error::EncodeJson { .. }
1014 | Error::DeserializePartitionExpr { .. }
1015 | Error::SerializePartitionExpr { .. } => StatusCode::Unexpected,
1016 Error::ViewNotFound { .. }
1017 | Error::ViewInfoNotFound { .. }
1018 | Error::TableNotFound { .. } => StatusCode::TableNotFound,
1019 Error::FlowNotFound { .. } => StatusCode::FlowNotFound,
1020 Error::JoinTask { .. } => StatusCode::Internal,
1021 Error::BuildParquetRecordBatchStream { .. }
1022 | Error::BuildFileStream { .. }
1023 | Error::WriteStreamToFile { .. }
1024 | Error::ReadDfRecordBatch { .. }
1025 | Error::Unexpected { .. } => StatusCode::Unexpected,
1026 Error::Catalog { source, .. } => source.status_code(),
1027 Error::BuildCreateExprOnInsertion { source, .. }
1028 | Error::FindNewColumnsOnInsertion { source, .. } => source.status_code(),
1029 Error::ExecuteStatement { source, .. }
1030 | Error::ExtractTableNames { source, .. }
1031 | Error::PlanStatement { source, .. }
1032 | Error::ParseQuery { source, .. }
1033 | Error::ExecLogicalPlan { source, .. }
1034 | Error::DescribeStatement { source, .. } => source.status_code(),
1035 Error::AlterExprToRequest { source, .. } => source.status_code(),
1036 Error::External { source, .. } => source.status_code(),
1037 Error::FindTablePartitionRule { source, .. }
1038 | Error::SplitInsert { source, .. }
1039 | Error::SplitDelete { source, .. }
1040 | Error::FindRegionLeader { source, .. } => source.status_code(),
1041 Error::UnrecognizedTableOption { .. } => StatusCode::InvalidArguments,
1042 Error::ReadObject { .. }
1043 | Error::ReadParquetMetadata { .. }
1044 | Error::ReadOrc { .. } => StatusCode::StorageUnavailable,
1045 Error::ListObjects { source, .. } | Error::BuildBackend { source, .. } => {
1046 source.status_code()
1047 }
1048 Error::ExecuteDdl { source, .. } => source.status_code(),
1049 Error::InvalidCopyParameter { .. } | Error::InvalidCopyDatabasePath { .. } => {
1050 StatusCode::InvalidArguments
1051 }
1052 Error::ColumnDefaultValue { source, .. } => source.status_code(),
1053 Error::EmptyDdlExpr { .. }
1054 | Error::InvalidPartitionRule { .. }
1055 | Error::ParseSqlValue { .. }
1056 | Error::InvalidTimestampRange { .. } => StatusCode::InvalidArguments,
1057 Error::CreateLogicalTables { .. } => StatusCode::Unexpected,
1058 Error::BuildRecordBatch { source, .. } => source.status_code(),
1059 Error::UpgradeCatalogManagerRef { .. } => StatusCode::Internal,
1060 Error::ColumnOptions { source, .. } => source.status_code(),
1061 Error::DecodeFlightData { source, .. } => source.status_code(),
1062 Error::ComputeArrow { .. } => StatusCode::Internal,
1063 Error::InvalidTimeIndexType { .. } | Error::InvalidTimezone { .. } => {
1064 StatusCode::InvalidArguments
1065 }
1066 Error::InvalidProcessId { .. } => StatusCode::InvalidArguments,
1067 Error::ProcessManagerMissing { .. } => StatusCode::Unexpected,
1068 Error::TimestampFormatNotSupported { .. } => StatusCode::InvalidArguments,
1069 Error::SqlCommon { source, .. } => source.status_code(),
1070 #[cfg(feature = "enterprise")]
1071 Error::InvalidTriggerName { .. } => StatusCode::InvalidArguments,
1072 #[cfg(feature = "enterprise")]
1073 Error::TooLargeDuration { .. } => StatusCode::InvalidArguments,
1074 #[cfg(feature = "enterprise")]
1075 Error::MissingTriggerQuerier { .. } => StatusCode::Internal,
1076 #[cfg(feature = "enterprise")]
1077 Error::TriggerQuerier { source, .. } => source.status_code(),
1078 }
1079 }
1080
1081 fn as_any(&self) -> &dyn Any {
1082 self
1083 }
1084
1085 fn retry_hint(&self) -> RetryHint {
1086 match self {
1087 Error::ReadObject { error, .. } => retry_hint_from_opendal_error(error),
1088 Error::ReadParquetMetadata { .. } => RetryHint::Retryable,
1089 Error::InvalidateTableCache { source, .. }
1090 | Error::ExecuteDdl { source, .. }
1091 | Error::RequestInserts { source, .. }
1092 | Error::RequestDeletes { source, .. }
1093 | Error::RequestRegion { source, .. }
1094 | Error::FindViewInfo { source, .. }
1095 | Error::TableMetadataManager { source, .. } => source.retry_hint(),
1096
1097 Error::ParseFileFormat { source, .. }
1098 | Error::InferSchema { source, .. }
1099 | Error::ListObjects { 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);