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("Unsupported format: {:?}", format))]
473 UnsupportedFormat {
474 #[snafu(implicit)]
475 location: Location,
476 format: Format,
477 },
478
479 #[snafu(display("Failed to parse file format"))]
480 ParseFileFormat {
481 #[snafu(implicit)]
482 location: Location,
483 source: common_datasource::error::Error,
484 },
485
486 #[snafu(display("Failed to build data source backend"))]
487 BuildBackend {
488 #[snafu(implicit)]
489 location: Location,
490 source: common_datasource::error::Error,
491 },
492
493 #[snafu(display("Failed to list objects"))]
494 ListObjects {
495 #[snafu(implicit)]
496 location: Location,
497 source: common_datasource::error::Error,
498 },
499
500 #[snafu(display("Failed to infer schema from path: {}", path))]
501 InferSchema {
502 path: String,
503 #[snafu(implicit)]
504 location: Location,
505 source: common_datasource::error::Error,
506 },
507
508 #[snafu(display("Failed to write stream to path: {}", path))]
509 WriteStreamToFile {
510 path: String,
511 #[snafu(implicit)]
512 location: Location,
513 source: common_datasource::error::Error,
514 },
515
516 #[snafu(display("Failed to read object in path: {}", path))]
517 ReadObject {
518 path: String,
519 #[snafu(implicit)]
520 location: Location,
521 #[snafu(source)]
522 error: object_store::Error,
523 },
524
525 #[snafu(display("Failed to read record batch"))]
526 ReadDfRecordBatch {
527 #[snafu(source)]
528 error: datafusion::error::DataFusionError,
529 #[snafu(implicit)]
530 location: Location,
531 },
532
533 #[snafu(display("Failed to read parquet file metadata"))]
534 ReadParquetMetadata {
535 #[snafu(source)]
536 error: parquet::errors::ParquetError,
537 #[snafu(implicit)]
538 location: Location,
539 },
540
541 #[snafu(display("Failed to build record batch"))]
542 BuildRecordBatch {
543 #[snafu(implicit)]
544 location: Location,
545 source: common_recordbatch::error::Error,
546 },
547
548 #[snafu(display("Failed to read orc schema"))]
549 ReadOrc {
550 source: common_datasource::error::Error,
551 #[snafu(implicit)]
552 location: Location,
553 },
554
555 #[snafu(display("Failed to build parquet record batch stream"))]
556 BuildParquetRecordBatchStream {
557 #[snafu(implicit)]
558 location: Location,
559 #[snafu(source)]
560 error: parquet::errors::ParquetError,
561 },
562
563 #[snafu(display("Failed to build file stream"))]
564 BuildFileStream {
565 #[snafu(implicit)]
566 location: Location,
567 #[snafu(source)]
568 error: common_datasource::error::Error,
569 },
570
571 #[snafu(display(
572 "Schema datatypes not match at index {}, expected table schema: {}, actual file schema: {}",
573 index,
574 table_schema,
575 file_schema
576 ))]
577 InvalidSchema {
578 index: usize,
579 table_schema: String,
580 file_schema: String,
581 #[snafu(implicit)]
582 location: Location,
583 },
584
585 #[snafu(display(
586 "CSV header mismatch in path: {}, unknown columns: {:?}, missing columns: {:?}, duplicate columns: {:?}",
587 path,
588 unknown_columns,
589 missing_columns,
590 duplicate_columns
591 ))]
592 CsvHeaderMismatch {
593 path: String,
594 unknown_columns: Vec<String>,
595 missing_columns: Vec<String>,
596 duplicate_columns: Vec<String>,
597 #[snafu(implicit)]
598 location: Location,
599 },
600
601 #[snafu(display("Failed to project schema"))]
602 ProjectSchema {
603 #[snafu(source)]
604 error: ArrowError,
605 #[snafu(implicit)]
606 location: Location,
607 },
608
609 #[snafu(display("Failed to encode object into json"))]
610 EncodeJson {
611 #[snafu(source)]
612 error: serde_json::error::Error,
613 #[snafu(implicit)]
614 location: Location,
615 },
616
617 #[snafu(display("Invalid COPY parameter, key: {}, value: {}", key, value))]
618 InvalidCopyParameter {
619 key: String,
620 value: String,
621 #[snafu(implicit)]
622 location: Location,
623 },
624
625 #[snafu(display("Invalid COPY DATABASE location, must end with '/': {}", value))]
626 InvalidCopyDatabasePath {
627 value: String,
628 #[snafu(implicit)]
629 location: Location,
630 },
631
632 #[snafu(display("Table metadata manager error"))]
633 TableMetadataManager {
634 source: common_meta::error::Error,
635 #[snafu(implicit)]
636 location: Location,
637 },
638
639 #[snafu(display("Missing insert body"))]
640 MissingInsertBody {
641 source: sql::error::Error,
642 #[snafu(implicit)]
643 location: Location,
644 },
645
646 #[snafu(display("Failed to parse sql value"))]
647 ParseSqlValue {
648 source: sql::error::Error,
649 #[snafu(implicit)]
650 location: Location,
651 },
652
653 #[snafu(display("Failed to build default value, column: {}", column))]
654 ColumnDefaultValue {
655 column: String,
656 #[snafu(implicit)]
657 location: Location,
658 source: datatypes::error::Error,
659 },
660
661 #[snafu(display(
662 "No valid default value can be built automatically, column: {}",
663 column,
664 ))]
665 ColumnNoneDefaultValue {
666 column: String,
667 #[snafu(implicit)]
668 location: Location,
669 },
670
671 #[snafu(display("Failed to prepare file table"))]
672 PrepareFileTable {
673 #[snafu(implicit)]
674 location: Location,
675 source: query::error::Error,
676 },
677
678 #[snafu(display("Failed to infer file table schema"))]
679 InferFileTableSchema {
680 #[snafu(implicit)]
681 location: Location,
682 source: query::error::Error,
683 },
684
685 #[snafu(display("The schema of the file table is incompatible with the table schema"))]
686 SchemaIncompatible {
687 #[snafu(implicit)]
688 location: Location,
689 source: query::error::Error,
690 },
691
692 #[snafu(display("Invalid table name: {}", table_name))]
693 InvalidTableName {
694 table_name: String,
695 #[snafu(implicit)]
696 location: Location,
697 },
698
699 #[snafu(display("Invalid view name: {name}"))]
700 InvalidViewName {
701 name: String,
702 #[snafu(implicit)]
703 location: Location,
704 },
705
706 #[snafu(display("Invalid flow name: {name}"))]
707 InvalidFlowName {
708 name: String,
709 #[snafu(implicit)]
710 location: Location,
711 },
712
713 #[cfg(feature = "enterprise")]
714 #[snafu(display("Invalid trigger name: {name}"))]
715 InvalidTriggerName {
716 name: String,
717 #[snafu(implicit)]
718 location: Location,
719 },
720
721 #[snafu(display("Empty {} expr", name))]
722 EmptyDdlExpr {
723 name: String,
724 #[snafu(implicit)]
725 location: Location,
726 },
727
728 #[snafu(display("Failed to create logical tables: {}", reason))]
729 CreateLogicalTables {
730 reason: String,
731 #[snafu(implicit)]
732 location: Location,
733 },
734
735 #[snafu(display("Invalid partition rule: {}", reason))]
736 InvalidPartitionRule {
737 reason: String,
738 #[snafu(implicit)]
739 location: Location,
740 },
741
742 #[snafu(display("Failed to serialize partition expression"))]
743 SerializePartitionExpr {
744 #[snafu(implicit)]
745 location: Location,
746 source: partition::error::Error,
747 },
748
749 #[snafu(display("Failed to deserialize partition expression"))]
750 DeserializePartitionExpr {
751 #[snafu(source)]
752 source: partition::error::Error,
753 #[snafu(implicit)]
754 location: Location,
755 },
756
757 #[snafu(display("Invalid configuration value."))]
758 InvalidConfigValue {
759 source: session::session_config::Error,
760 #[snafu(implicit)]
761 location: Location,
762 },
763
764 #[snafu(display("Invalid timestamp range, start: `{}`, end: `{}`", start, end))]
765 InvalidTimestampRange {
766 start: String,
767 end: String,
768 #[snafu(implicit)]
769 location: Location,
770 },
771
772 #[snafu(display("Failed to convert between logical plan and substrait plan"))]
773 SubstraitCodec {
774 #[snafu(implicit)]
775 location: Location,
776 source: substrait::error::Error,
777 },
778
779 #[snafu(display(
780 "Show create table only for base table. {} is {}",
781 table_name,
782 table_type
783 ))]
784 ShowCreateTableBaseOnly {
785 table_name: String,
786 table_type: TableType,
787 #[snafu(implicit)]
788 location: Location,
789 },
790 #[snafu(display("Create physical expr error"))]
791 PhysicalExpr {
792 #[snafu(source)]
793 error: common_recordbatch::error::Error,
794 #[snafu(implicit)]
795 location: Location,
796 },
797
798 #[snafu(display("Failed to upgrade catalog manager reference"))]
799 UpgradeCatalogManagerRef {
800 #[snafu(implicit)]
801 location: Location,
802 },
803
804 #[snafu(display("Invalid json text: {}", json))]
805 InvalidJsonFormat {
806 #[snafu(implicit)]
807 location: Location,
808 json: String,
809 },
810
811 #[snafu(display("Cursor {name} is not found"))]
812 CursorNotFound { name: String },
813
814 #[snafu(display("A cursor named {name} already exists"))]
815 CursorExists { name: String },
816
817 #[snafu(display("Column options error"))]
818 ColumnOptions {
819 #[snafu(source)]
820 source: api::error::Error,
821 #[snafu(implicit)]
822 location: Location,
823 },
824
825 #[snafu(display("Failed to create partition rules"))]
826 CreatePartitionRules {
827 #[snafu(source)]
828 source: sql::error::Error,
829 #[snafu(implicit)]
830 location: Location,
831 },
832
833 #[snafu(display("Failed to decode arrow flight data"))]
834 DecodeFlightData {
835 source: common_grpc::error::Error,
836 #[snafu(implicit)]
837 location: Location,
838 },
839
840 #[snafu(display("Failed to perform arrow compute"))]
841 ComputeArrow {
842 #[snafu(source)]
843 error: ArrowError,
844 #[snafu(implicit)]
845 location: Location,
846 },
847
848 #[snafu(display("Invalid time index type: {}", ty))]
849 InvalidTimeIndexType {
850 ty: arrow::datatypes::DataType,
851 #[snafu(implicit)]
852 location: Location,
853 },
854
855 #[snafu(display("Invalid timezone: {}", timezone))]
856 InvalidTimezone {
857 timezone: String,
858 #[snafu(source)]
859 source: common_time::error::Error,
860 #[snafu(implicit)]
861 location: Location,
862 },
863
864 #[snafu(display("Invalid process id: {}", id))]
865 InvalidProcessId { id: String },
866
867 #[snafu(display("ProcessManager is not present, this can be caused by misconfiguration."))]
868 ProcessManagerMissing {
869 #[snafu(implicit)]
870 location: Location,
871 },
872
873 #[snafu(display("Sql common error"))]
874 SqlCommon {
875 source: common_sql::error::Error,
876 #[snafu(implicit)]
877 location: Location,
878 },
879
880 #[snafu(display("Failed to convert partition expression to protobuf"))]
881 PartitionExprToPb {
882 source: partition::error::Error,
883 #[snafu(implicit)]
884 location: Location,
885 },
886
887 #[snafu(display(
888 "{} not supported when transforming to {} format type",
889 format,
890 file_format
891 ))]
892 TimestampFormatNotSupported {
893 file_format: String,
894 format: String,
895 #[snafu(implicit)]
896 location: Location,
897 },
898
899 #[cfg(feature = "enterprise")]
900 #[snafu(display("Too large duration"))]
901 TooLargeDuration {
902 #[snafu(source)]
903 error: prost_types::DurationError,
904 #[snafu(implicit)]
905 location: Location,
906 },
907
908 #[cfg(feature = "enterprise")]
909 #[snafu(display("Not trigger querier is specified"))]
910 MissingTriggerQuerier {
911 #[snafu(implicit)]
912 location: Location,
913 },
914
915 #[cfg(feature = "enterprise")]
916 #[snafu(display("Trigger querier error"))]
917 TriggerQuerier {
918 source: BoxedError,
919 #[snafu(implicit)]
920 location: Location,
921 },
922}
923
924pub type Result<T> = std::result::Result<T, Error>;
925
926impl ErrorExt for Error {
927 fn status_code(&self) -> StatusCode {
928 match self {
929 Error::Cast { source, .. } => source.status_code(),
930 Error::InvalidSql { .. }
931 | Error::InvalidConfigValue { .. }
932 | Error::InvalidInsertRequest { .. }
933 | Error::InvalidDeleteRequest { .. }
934 | Error::IllegalPrimaryKeysDef { .. }
935 | Error::SchemaNotFound { .. }
936 | Error::SchemaExists { .. }
937 | Error::SchemaInUse { .. }
938 | Error::ColumnNotFound { .. }
939 | Error::BuildRegex { .. }
940 | Error::InvalidSchema { .. }
941 | Error::CsvHeaderMismatch { .. }
942 | Error::ProjectSchema { .. }
943 | Error::UnsupportedFormat { .. }
944 | Error::ColumnNoneDefaultValue { .. }
945 | Error::PrepareFileTable { .. }
946 | Error::InferFileTableSchema { .. }
947 | Error::SchemaIncompatible { .. }
948 | Error::ConvertSchema { .. }
949 | Error::UnsupportedRegionRequest { .. }
950 | Error::InvalidTableName { .. }
951 | Error::InvalidViewName { .. }
952 | Error::InvalidFlowName { .. }
953 | Error::InvalidView { .. }
954 | Error::InvalidExpr { .. }
955 | Error::AdminFunctionNotFound { .. }
956 | Error::ViewColumnsMismatch { .. }
957 | Error::InvalidViewStmt { .. }
958 | Error::ConvertIdentifier { .. }
959 | Error::BuildAdminFunctionArgs { .. }
960 | Error::FunctionArityMismatch { .. }
961 | Error::InvalidPartition { .. }
962 | Error::PhysicalExpr { .. }
963 | Error::InvalidJsonFormat { .. }
964 | Error::PartitionExprToPb { .. }
965 | Error::CursorNotFound { .. }
966 | Error::CursorExists { .. }
967 | Error::CreatePartitionRules { .. } => StatusCode::InvalidArguments,
968 Error::TableAlreadyExists { .. } | Error::ViewAlreadyExists { .. } => {
969 StatusCode::TableAlreadyExists
970 }
971 Error::NotSupported { .. }
972 | Error::ShowCreateTableBaseOnly { .. }
973 | Error::SchemaReadOnly { .. } => StatusCode::Unsupported,
974 Error::TableMetadataManager { source, .. } => source.status_code(),
975 Error::ParseSql { source, .. } => source.status_code(),
976 Error::InvalidateTableCache { source, .. } => source.status_code(),
977 Error::ParseFileFormat { source, .. } | Error::InferSchema { source, .. } => {
978 source.status_code()
979 }
980 Error::Table { source, .. } | Error::Insert { source, .. } => source.status_code(),
981 Error::ConvertColumnDefaultConstraint { source, .. }
982 | Error::IntoVectors { source, .. } => source.status_code(),
983 Error::RequestInserts { source, .. } | Error::FindViewInfo { source, .. } => {
984 source.status_code()
985 }
986 Error::RequestRegion { source, .. } => source.status_code(),
987 Error::RequestDeletes { source, .. } => source.status_code(),
988 Error::SubstraitCodec { source, .. } => source.status_code(),
989 Error::ColumnDataType { source, .. } | Error::InvalidColumnDef { source, .. } => {
990 source.status_code()
991 }
992 Error::MissingTimeIndexColumn { source, .. } => source.status_code(),
993 Error::BuildDfLogicalPlan { .. }
994 | Error::BuildTableMeta { .. }
995 | Error::MissingInsertBody { .. } => StatusCode::Internal,
996 Error::ExecuteAdminFunction { .. }
997 | Error::EncodeJson { .. }
998 | Error::DeserializePartitionExpr { .. }
999 | Error::SerializePartitionExpr { .. } => StatusCode::Unexpected,
1000 Error::ViewNotFound { .. }
1001 | Error::ViewInfoNotFound { .. }
1002 | Error::TableNotFound { .. } => StatusCode::TableNotFound,
1003 Error::FlowNotFound { .. } => StatusCode::FlowNotFound,
1004 Error::JoinTask { .. } => StatusCode::Internal,
1005 Error::BuildParquetRecordBatchStream { .. }
1006 | Error::BuildFileStream { .. }
1007 | Error::WriteStreamToFile { .. }
1008 | Error::ReadDfRecordBatch { .. }
1009 | Error::Unexpected { .. } => StatusCode::Unexpected,
1010 Error::Catalog { source, .. } => source.status_code(),
1011 Error::BuildCreateExprOnInsertion { source, .. }
1012 | Error::FindNewColumnsOnInsertion { source, .. } => source.status_code(),
1013 Error::ExecuteStatement { source, .. }
1014 | Error::ExtractTableNames { source, .. }
1015 | Error::PlanStatement { source, .. }
1016 | Error::ParseQuery { source, .. }
1017 | Error::ExecLogicalPlan { source, .. }
1018 | Error::DescribeStatement { source, .. } => source.status_code(),
1019 Error::AlterExprToRequest { source, .. } => source.status_code(),
1020 Error::External { source, .. } => source.status_code(),
1021 Error::FindTablePartitionRule { source, .. }
1022 | Error::SplitInsert { source, .. }
1023 | Error::SplitDelete { source, .. }
1024 | Error::FindRegionLeader { source, .. } => source.status_code(),
1025 Error::UnrecognizedTableOption { .. } => StatusCode::InvalidArguments,
1026 Error::ReadObject { .. }
1027 | Error::ReadParquetMetadata { .. }
1028 | Error::ReadOrc { .. } => StatusCode::StorageUnavailable,
1029 Error::ListObjects { source, .. } | Error::BuildBackend { source, .. } => {
1030 source.status_code()
1031 }
1032 Error::ExecuteDdl { source, .. } => source.status_code(),
1033 Error::InvalidCopyParameter { .. } | Error::InvalidCopyDatabasePath { .. } => {
1034 StatusCode::InvalidArguments
1035 }
1036 Error::ColumnDefaultValue { source, .. } => source.status_code(),
1037 Error::EmptyDdlExpr { .. }
1038 | Error::InvalidPartitionRule { .. }
1039 | Error::ParseSqlValue { .. }
1040 | Error::InvalidTimestampRange { .. } => StatusCode::InvalidArguments,
1041 Error::CreateLogicalTables { .. } => StatusCode::Unexpected,
1042 Error::BuildRecordBatch { source, .. } => source.status_code(),
1043 Error::UpgradeCatalogManagerRef { .. } => StatusCode::Internal,
1044 Error::ColumnOptions { source, .. } => source.status_code(),
1045 Error::DecodeFlightData { source, .. } => source.status_code(),
1046 Error::ComputeArrow { .. } => StatusCode::Internal,
1047 Error::InvalidTimeIndexType { .. } | Error::InvalidTimezone { .. } => {
1048 StatusCode::InvalidArguments
1049 }
1050 Error::InvalidProcessId { .. } => StatusCode::InvalidArguments,
1051 Error::ProcessManagerMissing { .. } => StatusCode::Unexpected,
1052 Error::TimestampFormatNotSupported { .. } => StatusCode::InvalidArguments,
1053 Error::SqlCommon { source, .. } => source.status_code(),
1054 #[cfg(feature = "enterprise")]
1055 Error::InvalidTriggerName { .. } => StatusCode::InvalidArguments,
1056 #[cfg(feature = "enterprise")]
1057 Error::TooLargeDuration { .. } => StatusCode::InvalidArguments,
1058 #[cfg(feature = "enterprise")]
1059 Error::MissingTriggerQuerier { .. } => StatusCode::Internal,
1060 #[cfg(feature = "enterprise")]
1061 Error::TriggerQuerier { source, .. } => source.status_code(),
1062 }
1063 }
1064
1065 fn as_any(&self) -> &dyn Any {
1066 self
1067 }
1068
1069 fn retry_hint(&self) -> RetryHint {
1070 match self {
1071 Error::ReadObject { error, .. } => retry_hint_from_opendal_error(error),
1072 Error::ReadParquetMetadata { .. } => RetryHint::Retryable,
1073 Error::InvalidateTableCache { source, .. }
1074 | Error::ExecuteDdl { source, .. }
1075 | Error::RequestInserts { source, .. }
1076 | Error::RequestDeletes { source, .. }
1077 | Error::RequestRegion { source, .. }
1078 | Error::FindViewInfo { source, .. }
1079 | Error::TableMetadataManager { source, .. } => source.retry_hint(),
1080
1081 Error::ParseFileFormat { source, .. }
1082 | Error::InferSchema { source, .. }
1083 | Error::ListObjects { source, .. }
1084 | Error::BuildBackend { source, .. }
1085 | Error::ReadOrc { source, .. } => source.retry_hint(),
1086
1087 Error::ExtractTableNames { source, .. }
1088 | Error::ExecuteStatement { source, .. }
1089 | Error::PlanStatement { source, .. }
1090 | Error::ParseQuery { source, .. }
1091 | Error::ExecLogicalPlan { source, .. }
1092 | Error::DescribeStatement { source, .. } => source.retry_hint(),
1093
1094 Error::FindTablePartitionRule { source, .. }
1095 | Error::SplitInsert { source, .. }
1096 | Error::SplitDelete { source, .. }
1097 | Error::FindRegionLeader { source, .. } => source.retry_hint(),
1098
1099 Error::BuildCreateExprOnInsertion { source, .. }
1100 | Error::FindNewColumnsOnInsertion { source, .. }
1101 | Error::AlterExprToRequest { source, .. } => source.retry_hint(),
1102
1103 Error::ConvertColumnDefaultConstraint { source, .. }
1104 | Error::IntoVectors { source, .. }
1105 | Error::ColumnDefaultValue { source, .. } => source.retry_hint(),
1106
1107 Error::ColumnDataType { source, .. }
1108 | Error::InvalidColumnDef { source, .. }
1109 | Error::ColumnOptions { source, .. } => source.retry_hint(),
1110
1111 Error::Table { source, .. }
1112 | Error::Insert { source, .. }
1113 | Error::MissingTimeIndexColumn { source, .. } => source.retry_hint(),
1114
1115 Error::Cast { source, .. } => source.retry_hint(),
1116 Error::ParseSql { source, .. } => source.retry_hint(),
1117 Error::Catalog { source, .. } => source.retry_hint(),
1118 Error::SubstraitCodec { source, .. } => source.retry_hint(),
1119 Error::External { source, .. } => source.retry_hint(),
1120 Error::BuildRecordBatch { source, .. } => source.retry_hint(),
1121 Error::DecodeFlightData { source, .. } => source.retry_hint(),
1122 Error::SqlCommon { source, .. } => source.retry_hint(),
1123 Error::ConvertSchema { source, .. } => source.retry_hint(),
1124 Error::WriteStreamToFile { source, .. } => source.retry_hint(),
1125 Error::PrepareFileTable { source, .. } | Error::InferFileTableSchema { source, .. } => {
1126 source.retry_hint()
1127 }
1128 #[cfg(feature = "enterprise")]
1129 Error::TriggerQuerier { source, .. } => source.retry_hint(),
1130 _ => RetryHint::NonRetryable,
1131 }
1132 }
1133}
1134
1135define_into_tonic_status!(Error);