Skip to main content

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