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