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