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: common_datasource::error::Error,
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("Failed to serialize partition expression"))]
740    SerializePartitionExpr {
741        #[snafu(implicit)]
742        location: Location,
743        source: partition::error::Error,
744    },
745
746    #[snafu(display("Failed to deserialize partition expression"))]
747    DeserializePartitionExpr {
748        #[snafu(source)]
749        source: partition::error::Error,
750        #[snafu(implicit)]
751        location: Location,
752    },
753
754    #[snafu(display("Invalid configuration value."))]
755    InvalidConfigValue {
756        source: session::session_config::Error,
757        #[snafu(implicit)]
758        location: Location,
759    },
760
761    #[snafu(display("Invalid timestamp range, start: `{}`, end: `{}`", start, end))]
762    InvalidTimestampRange {
763        start: String,
764        end: String,
765        #[snafu(implicit)]
766        location: Location,
767    },
768
769    #[snafu(display("Failed to convert between logical plan and substrait plan"))]
770    SubstraitCodec {
771        #[snafu(implicit)]
772        location: Location,
773        source: substrait::error::Error,
774    },
775
776    #[snafu(display(
777        "Show create table only for base table. {} is {}",
778        table_name,
779        table_type
780    ))]
781    ShowCreateTableBaseOnly {
782        table_name: String,
783        table_type: TableType,
784        #[snafu(implicit)]
785        location: Location,
786    },
787    #[snafu(display("Create physical expr error"))]
788    PhysicalExpr {
789        #[snafu(source)]
790        error: common_recordbatch::error::Error,
791        #[snafu(implicit)]
792        location: Location,
793    },
794
795    #[snafu(display("Failed to upgrade catalog manager reference"))]
796    UpgradeCatalogManagerRef {
797        #[snafu(implicit)]
798        location: Location,
799    },
800
801    #[snafu(display("Invalid json text: {}", json))]
802    InvalidJsonFormat {
803        #[snafu(implicit)]
804        location: Location,
805        json: String,
806    },
807
808    #[snafu(display("Cursor {name} is not found"))]
809    CursorNotFound { name: String },
810
811    #[snafu(display("A cursor named {name} already exists"))]
812    CursorExists { name: String },
813
814    #[snafu(display("Column options error"))]
815    ColumnOptions {
816        #[snafu(source)]
817        source: api::error::Error,
818        #[snafu(implicit)]
819        location: Location,
820    },
821
822    #[snafu(display("Failed to create partition rules"))]
823    CreatePartitionRules {
824        #[snafu(source)]
825        source: sql::error::Error,
826        #[snafu(implicit)]
827        location: Location,
828    },
829
830    #[snafu(display("Failed to decode arrow flight data"))]
831    DecodeFlightData {
832        source: common_grpc::error::Error,
833        #[snafu(implicit)]
834        location: Location,
835    },
836
837    #[snafu(display("Failed to perform arrow compute"))]
838    ComputeArrow {
839        #[snafu(source)]
840        error: ArrowError,
841        #[snafu(implicit)]
842        location: Location,
843    },
844
845    #[snafu(display("Path not found: {path}"))]
846    PathNotFound {
847        path: String,
848        #[snafu(implicit)]
849        location: Location,
850    },
851
852    #[snafu(display("Invalid time index type: {}", ty))]
853    InvalidTimeIndexType {
854        ty: arrow::datatypes::DataType,
855        #[snafu(implicit)]
856        location: Location,
857    },
858
859    #[snafu(display("Invalid process id: {}", id))]
860    InvalidProcessId { id: String },
861
862    #[snafu(display("ProcessManager is not present, this can be caused by misconfiguration."))]
863    ProcessManagerMissing {
864        #[snafu(implicit)]
865        location: Location,
866    },
867
868    #[snafu(display("Sql common error"))]
869    SqlCommon {
870        source: common_sql::error::Error,
871        #[snafu(implicit)]
872        location: Location,
873    },
874
875    #[snafu(display("Failed to convert partition expression to protobuf"))]
876    PartitionExprToPb {
877        source: partition::error::Error,
878        #[snafu(implicit)]
879        location: Location,
880    },
881
882    #[snafu(display(
883        "{} not supported when transforming to {} format type",
884        format,
885        file_format
886    ))]
887    TimestampFormatNotSupported {
888        file_format: String,
889        format: String,
890        #[snafu(implicit)]
891        location: Location,
892    },
893
894    #[cfg(feature = "enterprise")]
895    #[snafu(display("Too large duration"))]
896    TooLargeDuration {
897        #[snafu(source)]
898        error: prost_types::DurationError,
899        #[snafu(implicit)]
900        location: Location,
901    },
902
903    #[cfg(feature = "enterprise")]
904    #[snafu(display("Not trigger querier is specified"))]
905    MissingTriggerQuerier {
906        #[snafu(implicit)]
907        location: Location,
908    },
909
910    #[cfg(feature = "enterprise")]
911    #[snafu(display("Trigger querier error"))]
912    TriggerQuerier {
913        source: BoxedError,
914        #[snafu(implicit)]
915        location: Location,
916    },
917}
918
919pub type Result<T> = std::result::Result<T, Error>;
920
921impl ErrorExt for Error {
922    fn status_code(&self) -> StatusCode {
923        match self {
924            Error::Cast { source, .. } => source.status_code(),
925            Error::InvalidSql { .. }
926            | Error::InvalidConfigValue { .. }
927            | Error::InvalidInsertRequest { .. }
928            | Error::InvalidDeleteRequest { .. }
929            | Error::IllegalPrimaryKeysDef { .. }
930            | Error::SchemaNotFound { .. }
931            | Error::SchemaExists { .. }
932            | Error::SchemaInUse { .. }
933            | Error::ColumnNotFound { .. }
934            | Error::BuildRegex { .. }
935            | Error::InvalidSchema { .. }
936            | Error::ProjectSchema { .. }
937            | Error::UnsupportedFormat { .. }
938            | Error::ColumnNoneDefaultValue { .. }
939            | Error::PrepareFileTable { .. }
940            | Error::InferFileTableSchema { .. }
941            | Error::SchemaIncompatible { .. }
942            | Error::ConvertSchema { .. }
943            | Error::UnsupportedRegionRequest { .. }
944            | Error::InvalidTableName { .. }
945            | Error::InvalidViewName { .. }
946            | Error::InvalidFlowName { .. }
947            | Error::InvalidView { .. }
948            | Error::InvalidExpr { .. }
949            | Error::AdminFunctionNotFound { .. }
950            | Error::ViewColumnsMismatch { .. }
951            | Error::InvalidViewStmt { .. }
952            | Error::ConvertIdentifier { .. }
953            | Error::BuildAdminFunctionArgs { .. }
954            | Error::FunctionArityMismatch { .. }
955            | Error::InvalidPartition { .. }
956            | Error::PhysicalExpr { .. }
957            | Error::InvalidJsonFormat { .. }
958            | Error::PartitionExprToPb { .. }
959            | Error::CursorNotFound { .. }
960            | Error::CursorExists { .. }
961            | Error::CreatePartitionRules { .. } => StatusCode::InvalidArguments,
962            Error::TableAlreadyExists { .. } | Error::ViewAlreadyExists { .. } => {
963                StatusCode::TableAlreadyExists
964            }
965            Error::NotSupported { .. }
966            | Error::ShowCreateTableBaseOnly { .. }
967            | Error::SchemaReadOnly { .. } => StatusCode::Unsupported,
968            Error::TableMetadataManager { source, .. } => source.status_code(),
969            Error::ParseSql { source, .. } => source.status_code(),
970            Error::InvalidateTableCache { source, .. } => source.status_code(),
971            Error::ParseFileFormat { source, .. } | Error::InferSchema { source, .. } => {
972                source.status_code()
973            }
974            Error::Table { source, .. } | Error::Insert { source, .. } => source.status_code(),
975            Error::ConvertColumnDefaultConstraint { source, .. }
976            | Error::CreateTableInfo { source, .. }
977            | Error::IntoVectors { source, .. } => source.status_code(),
978            Error::RequestInserts { source, .. } | Error::FindViewInfo { source, .. } => {
979                source.status_code()
980            }
981            Error::RequestRegion { source, .. } => source.status_code(),
982            Error::RequestDeletes { source, .. } => source.status_code(),
983            Error::SubstraitCodec { source, .. } => source.status_code(),
984            Error::ColumnDataType { source, .. } | Error::InvalidColumnDef { source, .. } => {
985                source.status_code()
986            }
987            Error::MissingTimeIndexColumn { source, .. } => source.status_code(),
988            Error::BuildDfLogicalPlan { .. }
989            | Error::BuildTableMeta { .. }
990            | Error::MissingInsertBody { .. } => StatusCode::Internal,
991            Error::ExecuteAdminFunction { .. }
992            | Error::EncodeJson { .. }
993            | Error::DeserializePartitionExpr { .. }
994            | Error::SerializePartitionExpr { .. } => StatusCode::Unexpected,
995            Error::ViewNotFound { .. }
996            | Error::ViewInfoNotFound { .. }
997            | Error::TableNotFound { .. } => StatusCode::TableNotFound,
998            Error::FlowNotFound { .. } => StatusCode::FlowNotFound,
999            Error::JoinTask { .. } => StatusCode::Internal,
1000            Error::BuildParquetRecordBatchStream { .. }
1001            | Error::BuildFileStream { .. }
1002            | Error::WriteStreamToFile { .. }
1003            | Error::ReadDfRecordBatch { .. }
1004            | Error::Unexpected { .. } => StatusCode::Unexpected,
1005            Error::Catalog { source, .. } => source.status_code(),
1006            Error::BuildCreateExprOnInsertion { source, .. }
1007            | Error::FindNewColumnsOnInsertion { source, .. } => source.status_code(),
1008            Error::ExecuteStatement { source, .. }
1009            | Error::ExtractTableNames { source, .. }
1010            | Error::PlanStatement { source, .. }
1011            | Error::ParseQuery { source, .. }
1012            | Error::ExecLogicalPlan { source, .. }
1013            | Error::DescribeStatement { source, .. } => source.status_code(),
1014            Error::AlterExprToRequest { source, .. } => source.status_code(),
1015            Error::External { source, .. } => source.status_code(),
1016            Error::FindTablePartitionRule { source, .. }
1017            | Error::SplitInsert { source, .. }
1018            | Error::SplitDelete { source, .. }
1019            | Error::FindRegionLeader { source, .. } => source.status_code(),
1020            Error::UnrecognizedTableOption { .. } => StatusCode::InvalidArguments,
1021            Error::ReadObject { .. }
1022            | Error::ReadParquetMetadata { .. }
1023            | Error::ReadOrc { .. } => StatusCode::StorageUnavailable,
1024            Error::ListObjects { source, .. }
1025            | Error::ParseUrl { source, .. }
1026            | Error::BuildBackend { source, .. } => source.status_code(),
1027            Error::ExecuteDdl { source, .. } => source.status_code(),
1028            Error::InvalidCopyParameter { .. } | Error::InvalidCopyDatabasePath { .. } => {
1029                StatusCode::InvalidArguments
1030            }
1031            Error::ColumnDefaultValue { source, .. } => source.status_code(),
1032            Error::EmptyDdlExpr { .. }
1033            | Error::InvalidPartitionRule { .. }
1034            | Error::ParseSqlValue { .. }
1035            | Error::InvalidTimestampRange { .. } => StatusCode::InvalidArguments,
1036            Error::CreateLogicalTables { .. } => StatusCode::Unexpected,
1037            Error::BuildRecordBatch { source, .. } => source.status_code(),
1038            Error::UpgradeCatalogManagerRef { .. } => StatusCode::Internal,
1039            Error::ColumnOptions { source, .. } => source.status_code(),
1040            Error::DecodeFlightData { source, .. } => source.status_code(),
1041            Error::ComputeArrow { .. } => StatusCode::Internal,
1042            Error::InvalidTimeIndexType { .. } => StatusCode::InvalidArguments,
1043            Error::InvalidProcessId { .. } => StatusCode::InvalidArguments,
1044            Error::ProcessManagerMissing { .. } => StatusCode::Unexpected,
1045            Error::PathNotFound { .. } => StatusCode::InvalidArguments,
1046            Error::TimestampFormatNotSupported { .. } => StatusCode::InvalidArguments,
1047            Error::SqlCommon { source, .. } => source.status_code(),
1048            #[cfg(feature = "enterprise")]
1049            Error::InvalidTriggerName { .. } => StatusCode::InvalidArguments,
1050            #[cfg(feature = "enterprise")]
1051            Error::TooLargeDuration { .. } => StatusCode::InvalidArguments,
1052            #[cfg(feature = "enterprise")]
1053            Error::MissingTriggerQuerier { .. } => StatusCode::Internal,
1054            #[cfg(feature = "enterprise")]
1055            Error::TriggerQuerier { source, .. } => source.status_code(),
1056        }
1057    }
1058
1059    fn as_any(&self) -> &dyn Any {
1060        self
1061    }
1062}
1063
1064define_into_tonic_status!(Error);