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