operator/
error.rs

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