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 build CreateExpr on insertion"))]
310    BuildCreateExprOnInsertion {
311        #[snafu(implicit)]
312        location: Location,
313        source: common_grpc_expr::error::Error,
314    },
315
316    #[snafu(display("Failed to find schema, schema info: {}", schema_info))]
317    SchemaNotFound {
318        schema_info: String,
319        #[snafu(implicit)]
320        location: Location,
321    },
322
323    #[snafu(display("Schema {} already exists", name))]
324    SchemaExists {
325        name: String,
326        #[snafu(implicit)]
327        location: Location,
328    },
329
330    #[snafu(display("Schema `{name}` is in use"))]
331    SchemaInUse {
332        name: String,
333        #[snafu(implicit)]
334        location: Location,
335    },
336
337    #[snafu(display("Schema `{name}` is read-only"))]
338    SchemaReadOnly {
339        name: String,
340        #[snafu(implicit)]
341        location: Location,
342    },
343
344    #[snafu(display("Table occurs error"))]
345    Table {
346        #[snafu(implicit)]
347        location: Location,
348        source: table::error::Error,
349    },
350
351    #[snafu(display("Cannot find column by name: {}", msg))]
352    ColumnNotFound {
353        msg: String,
354        #[snafu(implicit)]
355        location: Location,
356    },
357
358    #[snafu(display("Failed to execute statement"))]
359    ExecuteStatement {
360        #[snafu(implicit)]
361        location: Location,
362        source: query::error::Error,
363    },
364
365    #[snafu(display("Failed to plan statement"))]
366    PlanStatement {
367        #[snafu(implicit)]
368        location: Location,
369        source: query::error::Error,
370    },
371
372    #[snafu(display("Failed to parse query"))]
373    ParseQuery {
374        #[snafu(implicit)]
375        location: Location,
376        source: query::error::Error,
377    },
378
379    #[snafu(display("Failed to execute logical plan"))]
380    ExecLogicalPlan {
381        #[snafu(implicit)]
382        location: Location,
383        source: query::error::Error,
384    },
385
386    #[snafu(display("Failed to build DataFusion logical plan"))]
387    BuildDfLogicalPlan {
388        #[snafu(source)]
389        error: datafusion_common::DataFusionError,
390        #[snafu(implicit)]
391        location: Location,
392    },
393
394    #[snafu(display("Failed to convert AlterExpr to AlterRequest"))]
395    AlterExprToRequest {
396        #[snafu(implicit)]
397        location: Location,
398        source: common_grpc_expr::error::Error,
399    },
400
401    #[snafu(display("Failed to build table meta for table: {}", table_name))]
402    BuildTableMeta {
403        table_name: String,
404        #[snafu(source)]
405        error: table::metadata::TableMetaBuilderError,
406        #[snafu(implicit)]
407        location: Location,
408    },
409
410    #[snafu(display("Not supported: {}", feat))]
411    NotSupported { feat: String },
412
413    #[snafu(display("Failed to find new columns on insertion"))]
414    FindNewColumnsOnInsertion {
415        #[snafu(implicit)]
416        location: Location,
417        source: common_grpc_expr::error::Error,
418    },
419
420    #[snafu(display("Failed to convert into vectors"))]
421    IntoVectors {
422        #[snafu(implicit)]
423        location: Location,
424        source: datatypes::error::Error,
425    },
426
427    #[snafu(display("Failed to describe schema for given statement"))]
428    DescribeStatement {
429        #[snafu(implicit)]
430        location: Location,
431        source: query::error::Error,
432    },
433
434    #[snafu(display("Illegal primary keys definition: {}", msg))]
435    IllegalPrimaryKeysDef {
436        msg: String,
437        #[snafu(implicit)]
438        location: Location,
439    },
440
441    #[snafu(display("Unrecognized table option"))]
442    UnrecognizedTableOption {
443        #[snafu(implicit)]
444        location: Location,
445        source: table::error::Error,
446    },
447
448    #[snafu(display("Missing time index column"))]
449    MissingTimeIndexColumn {
450        #[snafu(implicit)]
451        location: Location,
452        source: table::error::Error,
453    },
454
455    #[snafu(display("Failed to build regex"))]
456    BuildRegex {
457        #[snafu(implicit)]
458        location: Location,
459        #[snafu(source)]
460        error: regex::Error,
461    },
462
463    #[snafu(display("Failed to insert value into table: {}", table_name))]
464    Insert {
465        table_name: String,
466        #[snafu(implicit)]
467        location: Location,
468        source: table::error::Error,
469    },
470
471    #[snafu(display("Failed to parse data source url"))]
472    ParseUrl {
473        #[snafu(implicit)]
474        location: Location,
475        source: common_datasource::error::Error,
476    },
477
478    #[snafu(display("Unsupported format: {:?}", format))]
479    UnsupportedFormat {
480        #[snafu(implicit)]
481        location: Location,
482        format: Format,
483    },
484
485    #[snafu(display("Failed to parse file format"))]
486    ParseFileFormat {
487        #[snafu(implicit)]
488        location: Location,
489        source: common_datasource::error::Error,
490    },
491
492    #[snafu(display("Failed to build data source backend"))]
493    BuildBackend {
494        #[snafu(implicit)]
495        location: Location,
496        source: common_datasource::error::Error,
497    },
498
499    #[snafu(display("Failed to list objects"))]
500    ListObjects {
501        #[snafu(implicit)]
502        location: Location,
503        source: common_datasource::error::Error,
504    },
505
506    #[snafu(display("Failed to infer schema from path: {}", path))]
507    InferSchema {
508        path: String,
509        #[snafu(implicit)]
510        location: Location,
511        source: common_datasource::error::Error,
512    },
513
514    #[snafu(display("Failed to write stream to path: {}", path))]
515    WriteStreamToFile {
516        path: String,
517        #[snafu(implicit)]
518        location: Location,
519        source: common_datasource::error::Error,
520    },
521
522    #[snafu(display("Failed to read object in path: {}", path))]
523    ReadObject {
524        path: String,
525        #[snafu(implicit)]
526        location: Location,
527        #[snafu(source)]
528        error: object_store::Error,
529    },
530
531    #[snafu(display("Failed to read record batch"))]
532    ReadDfRecordBatch {
533        #[snafu(source)]
534        error: datafusion::error::DataFusionError,
535        #[snafu(implicit)]
536        location: Location,
537    },
538
539    #[snafu(display("Failed to read parquet file metadata"))]
540    ReadParquetMetadata {
541        #[snafu(source)]
542        error: parquet::errors::ParquetError,
543        #[snafu(implicit)]
544        location: Location,
545    },
546
547    #[snafu(display("Failed to build record batch"))]
548    BuildRecordBatch {
549        #[snafu(implicit)]
550        location: Location,
551        source: common_recordbatch::error::Error,
552    },
553
554    #[snafu(display("Failed to read orc schema"))]
555    ReadOrc {
556        source: common_datasource::error::Error,
557        #[snafu(implicit)]
558        location: Location,
559    },
560
561    #[snafu(display("Failed to build parquet record batch stream"))]
562    BuildParquetRecordBatchStream {
563        #[snafu(implicit)]
564        location: Location,
565        #[snafu(source)]
566        error: parquet::errors::ParquetError,
567    },
568
569    #[snafu(display("Failed to build file stream"))]
570    BuildFileStream {
571        #[snafu(implicit)]
572        location: Location,
573        #[snafu(source)]
574        error: common_datasource::error::Error,
575    },
576
577    #[snafu(display(
578        "Schema datatypes not match at index {}, expected table schema: {}, actual file schema: {}",
579        index,
580        table_schema,
581        file_schema
582    ))]
583    InvalidSchema {
584        index: usize,
585        table_schema: String,
586        file_schema: String,
587        #[snafu(implicit)]
588        location: Location,
589    },
590
591    #[snafu(display("Failed to project schema"))]
592    ProjectSchema {
593        #[snafu(source)]
594        error: ArrowError,
595        #[snafu(implicit)]
596        location: Location,
597    },
598
599    #[snafu(display("Failed to encode object into json"))]
600    EncodeJson {
601        #[snafu(source)]
602        error: serde_json::error::Error,
603        #[snafu(implicit)]
604        location: Location,
605    },
606
607    #[snafu(display("Invalid COPY parameter, key: {}, value: {}", key, value))]
608    InvalidCopyParameter {
609        key: String,
610        value: String,
611        #[snafu(implicit)]
612        location: Location,
613    },
614
615    #[snafu(display("Invalid COPY DATABASE location, must end with '/': {}", value))]
616    InvalidCopyDatabasePath {
617        value: String,
618        #[snafu(implicit)]
619        location: Location,
620    },
621
622    #[snafu(display("Table metadata manager error"))]
623    TableMetadataManager {
624        source: common_meta::error::Error,
625        #[snafu(implicit)]
626        location: Location,
627    },
628
629    #[snafu(display("Missing insert body"))]
630    MissingInsertBody {
631        source: sql::error::Error,
632        #[snafu(implicit)]
633        location: Location,
634    },
635
636    #[snafu(display("Failed to parse sql value"))]
637    ParseSqlValue {
638        source: sql::error::Error,
639        #[snafu(implicit)]
640        location: Location,
641    },
642
643    #[snafu(display("Failed to build default value, column: {}", column))]
644    ColumnDefaultValue {
645        column: String,
646        #[snafu(implicit)]
647        location: Location,
648        source: datatypes::error::Error,
649    },
650
651    #[snafu(display(
652        "No valid default value can be built automatically, column: {}",
653        column,
654    ))]
655    ColumnNoneDefaultValue {
656        column: String,
657        #[snafu(implicit)]
658        location: Location,
659    },
660
661    #[snafu(display("Failed to prepare file table"))]
662    PrepareFileTable {
663        #[snafu(implicit)]
664        location: Location,
665        source: query::error::Error,
666    },
667
668    #[snafu(display("Failed to infer file table schema"))]
669    InferFileTableSchema {
670        #[snafu(implicit)]
671        location: Location,
672        source: query::error::Error,
673    },
674
675    #[snafu(display("The schema of the file table is incompatible with the table schema"))]
676    SchemaIncompatible {
677        #[snafu(implicit)]
678        location: Location,
679        source: query::error::Error,
680    },
681
682    #[snafu(display("Invalid table name: {}", table_name))]
683    InvalidTableName {
684        table_name: String,
685        #[snafu(implicit)]
686        location: Location,
687    },
688
689    #[snafu(display("Invalid view name: {name}"))]
690    InvalidViewName {
691        name: String,
692        #[snafu(implicit)]
693        location: Location,
694    },
695
696    #[snafu(display("Invalid flow name: {name}"))]
697    InvalidFlowName {
698        name: String,
699        #[snafu(implicit)]
700        location: Location,
701    },
702
703    #[cfg(feature = "enterprise")]
704    #[snafu(display("Invalid trigger name: {name}"))]
705    InvalidTriggerName {
706        name: String,
707        #[snafu(implicit)]
708        location: Location,
709    },
710
711    #[snafu(display("Empty {} expr", name))]
712    EmptyDdlExpr {
713        name: String,
714        #[snafu(implicit)]
715        location: Location,
716    },
717
718    #[snafu(display("Failed to create logical tables: {}", reason))]
719    CreateLogicalTables {
720        reason: String,
721        #[snafu(implicit)]
722        location: Location,
723    },
724
725    #[snafu(display("Invalid partition rule: {}", reason))]
726    InvalidPartitionRule {
727        reason: String,
728        #[snafu(implicit)]
729        location: Location,
730    },
731
732    #[snafu(display("Failed to serialize partition expression"))]
733    SerializePartitionExpr {
734        #[snafu(implicit)]
735        location: Location,
736        source: partition::error::Error,
737    },
738
739    #[snafu(display("Failed to deserialize partition expression"))]
740    DeserializePartitionExpr {
741        #[snafu(source)]
742        source: partition::error::Error,
743        #[snafu(implicit)]
744        location: Location,
745    },
746
747    #[snafu(display("Invalid configuration value."))]
748    InvalidConfigValue {
749        source: session::session_config::Error,
750        #[snafu(implicit)]
751        location: Location,
752    },
753
754    #[snafu(display("Invalid timestamp range, start: `{}`, end: `{}`", start, end))]
755    InvalidTimestampRange {
756        start: String,
757        end: String,
758        #[snafu(implicit)]
759        location: Location,
760    },
761
762    #[snafu(display("Failed to convert between logical plan and substrait plan"))]
763    SubstraitCodec {
764        #[snafu(implicit)]
765        location: Location,
766        source: substrait::error::Error,
767    },
768
769    #[snafu(display(
770        "Show create table only for base table. {} is {}",
771        table_name,
772        table_type
773    ))]
774    ShowCreateTableBaseOnly {
775        table_name: String,
776        table_type: TableType,
777        #[snafu(implicit)]
778        location: Location,
779    },
780    #[snafu(display("Create physical expr error"))]
781    PhysicalExpr {
782        #[snafu(source)]
783        error: common_recordbatch::error::Error,
784        #[snafu(implicit)]
785        location: Location,
786    },
787
788    #[snafu(display("Failed to upgrade catalog manager reference"))]
789    UpgradeCatalogManagerRef {
790        #[snafu(implicit)]
791        location: Location,
792    },
793
794    #[snafu(display("Invalid json text: {}", json))]
795    InvalidJsonFormat {
796        #[snafu(implicit)]
797        location: Location,
798        json: String,
799    },
800
801    #[snafu(display("Cursor {name} is not found"))]
802    CursorNotFound { name: String },
803
804    #[snafu(display("A cursor named {name} already exists"))]
805    CursorExists { name: String },
806
807    #[snafu(display("Column options error"))]
808    ColumnOptions {
809        #[snafu(source)]
810        source: api::error::Error,
811        #[snafu(implicit)]
812        location: Location,
813    },
814
815    #[snafu(display("Failed to create partition rules"))]
816    CreatePartitionRules {
817        #[snafu(source)]
818        source: sql::error::Error,
819        #[snafu(implicit)]
820        location: Location,
821    },
822
823    #[snafu(display("Failed to decode arrow flight data"))]
824    DecodeFlightData {
825        source: common_grpc::error::Error,
826        #[snafu(implicit)]
827        location: Location,
828    },
829
830    #[snafu(display("Failed to perform arrow compute"))]
831    ComputeArrow {
832        #[snafu(source)]
833        error: ArrowError,
834        #[snafu(implicit)]
835        location: Location,
836    },
837
838    #[snafu(display("Path not found: {path}"))]
839    PathNotFound {
840        path: String,
841        #[snafu(implicit)]
842        location: Location,
843    },
844
845    #[snafu(display("Invalid time index type: {}", ty))]
846    InvalidTimeIndexType {
847        ty: arrow::datatypes::DataType,
848        #[snafu(implicit)]
849        location: Location,
850    },
851
852    #[snafu(display("Invalid timezone: {}", timezone))]
853    InvalidTimezone {
854        timezone: String,
855        #[snafu(source)]
856        source: common_time::error::Error,
857        #[snafu(implicit)]
858        location: Location,
859    },
860
861    #[snafu(display("Invalid process id: {}", id))]
862    InvalidProcessId { id: String },
863
864    #[snafu(display("ProcessManager is not present, this can be caused by misconfiguration."))]
865    ProcessManagerMissing {
866        #[snafu(implicit)]
867        location: Location,
868    },
869
870    #[snafu(display("Sql common error"))]
871    SqlCommon {
872        source: common_sql::error::Error,
873        #[snafu(implicit)]
874        location: Location,
875    },
876
877    #[snafu(display("Failed to convert partition expression to protobuf"))]
878    PartitionExprToPb {
879        source: partition::error::Error,
880        #[snafu(implicit)]
881        location: Location,
882    },
883
884    #[snafu(display(
885        "{} not supported when transforming to {} format type",
886        format,
887        file_format
888    ))]
889    TimestampFormatNotSupported {
890        file_format: String,
891        format: String,
892        #[snafu(implicit)]
893        location: Location,
894    },
895
896    #[cfg(feature = "enterprise")]
897    #[snafu(display("Too large duration"))]
898    TooLargeDuration {
899        #[snafu(source)]
900        error: prost_types::DurationError,
901        #[snafu(implicit)]
902        location: Location,
903    },
904
905    #[cfg(feature = "enterprise")]
906    #[snafu(display("Not trigger querier is specified"))]
907    MissingTriggerQuerier {
908        #[snafu(implicit)]
909        location: Location,
910    },
911
912    #[cfg(feature = "enterprise")]
913    #[snafu(display("Trigger querier error"))]
914    TriggerQuerier {
915        source: BoxedError,
916        #[snafu(implicit)]
917        location: Location,
918    },
919}
920
921pub type Result<T> = std::result::Result<T, Error>;
922
923impl ErrorExt for Error {
924    fn status_code(&self) -> StatusCode {
925        match self {
926            Error::Cast { source, .. } => source.status_code(),
927            Error::InvalidSql { .. }
928            | Error::InvalidConfigValue { .. }
929            | Error::InvalidInsertRequest { .. }
930            | Error::InvalidDeleteRequest { .. }
931            | Error::IllegalPrimaryKeysDef { .. }
932            | Error::SchemaNotFound { .. }
933            | Error::SchemaExists { .. }
934            | Error::SchemaInUse { .. }
935            | Error::ColumnNotFound { .. }
936            | Error::BuildRegex { .. }
937            | Error::InvalidSchema { .. }
938            | Error::ProjectSchema { .. }
939            | Error::UnsupportedFormat { .. }
940            | Error::ColumnNoneDefaultValue { .. }
941            | Error::PrepareFileTable { .. }
942            | Error::InferFileTableSchema { .. }
943            | Error::SchemaIncompatible { .. }
944            | Error::ConvertSchema { .. }
945            | Error::UnsupportedRegionRequest { .. }
946            | Error::InvalidTableName { .. }
947            | Error::InvalidViewName { .. }
948            | Error::InvalidFlowName { .. }
949            | Error::InvalidView { .. }
950            | Error::InvalidExpr { .. }
951            | Error::AdminFunctionNotFound { .. }
952            | Error::ViewColumnsMismatch { .. }
953            | Error::InvalidViewStmt { .. }
954            | Error::ConvertIdentifier { .. }
955            | Error::BuildAdminFunctionArgs { .. }
956            | Error::FunctionArityMismatch { .. }
957            | Error::InvalidPartition { .. }
958            | Error::PhysicalExpr { .. }
959            | Error::InvalidJsonFormat { .. }
960            | Error::PartitionExprToPb { .. }
961            | Error::CursorNotFound { .. }
962            | Error::CursorExists { .. }
963            | Error::CreatePartitionRules { .. } => StatusCode::InvalidArguments,
964            Error::TableAlreadyExists { .. } | Error::ViewAlreadyExists { .. } => {
965                StatusCode::TableAlreadyExists
966            }
967            Error::NotSupported { .. }
968            | Error::ShowCreateTableBaseOnly { .. }
969            | Error::SchemaReadOnly { .. } => StatusCode::Unsupported,
970            Error::TableMetadataManager { source, .. } => source.status_code(),
971            Error::ParseSql { source, .. } => source.status_code(),
972            Error::InvalidateTableCache { source, .. } => source.status_code(),
973            Error::ParseFileFormat { source, .. } | Error::InferSchema { source, .. } => {
974                source.status_code()
975            }
976            Error::Table { source, .. } | Error::Insert { source, .. } => source.status_code(),
977            Error::ConvertColumnDefaultConstraint { source, .. }
978            | Error::IntoVectors { source, .. } => source.status_code(),
979            Error::RequestInserts { source, .. } | Error::FindViewInfo { source, .. } => {
980                source.status_code()
981            }
982            Error::RequestRegion { source, .. } => source.status_code(),
983            Error::RequestDeletes { source, .. } => source.status_code(),
984            Error::SubstraitCodec { source, .. } => source.status_code(),
985            Error::ColumnDataType { source, .. } | Error::InvalidColumnDef { source, .. } => {
986                source.status_code()
987            }
988            Error::MissingTimeIndexColumn { source, .. } => source.status_code(),
989            Error::BuildDfLogicalPlan { .. }
990            | Error::BuildTableMeta { .. }
991            | Error::MissingInsertBody { .. } => StatusCode::Internal,
992            Error::ExecuteAdminFunction { .. }
993            | Error::EncodeJson { .. }
994            | Error::DeserializePartitionExpr { .. }
995            | Error::SerializePartitionExpr { .. } => StatusCode::Unexpected,
996            Error::ViewNotFound { .. }
997            | Error::ViewInfoNotFound { .. }
998            | Error::TableNotFound { .. } => StatusCode::TableNotFound,
999            Error::FlowNotFound { .. } => StatusCode::FlowNotFound,
1000            Error::JoinTask { .. } => StatusCode::Internal,
1001            Error::BuildParquetRecordBatchStream { .. }
1002            | Error::BuildFileStream { .. }
1003            | Error::WriteStreamToFile { .. }
1004            | Error::ReadDfRecordBatch { .. }
1005            | Error::Unexpected { .. } => StatusCode::Unexpected,
1006            Error::Catalog { source, .. } => source.status_code(),
1007            Error::BuildCreateExprOnInsertion { source, .. }
1008            | Error::FindNewColumnsOnInsertion { source, .. } => source.status_code(),
1009            Error::ExecuteStatement { source, .. }
1010            | Error::ExtractTableNames { source, .. }
1011            | Error::PlanStatement { source, .. }
1012            | Error::ParseQuery { source, .. }
1013            | Error::ExecLogicalPlan { source, .. }
1014            | Error::DescribeStatement { source, .. } => source.status_code(),
1015            Error::AlterExprToRequest { source, .. } => source.status_code(),
1016            Error::External { source, .. } => source.status_code(),
1017            Error::FindTablePartitionRule { source, .. }
1018            | Error::SplitInsert { source, .. }
1019            | Error::SplitDelete { source, .. }
1020            | Error::FindRegionLeader { source, .. } => source.status_code(),
1021            Error::UnrecognizedTableOption { .. } => StatusCode::InvalidArguments,
1022            Error::ReadObject { .. }
1023            | Error::ReadParquetMetadata { .. }
1024            | Error::ReadOrc { .. } => StatusCode::StorageUnavailable,
1025            Error::ListObjects { source, .. }
1026            | Error::ParseUrl { source, .. }
1027            | Error::BuildBackend { source, .. } => source.status_code(),
1028            Error::ExecuteDdl { source, .. } => source.status_code(),
1029            Error::InvalidCopyParameter { .. } | Error::InvalidCopyDatabasePath { .. } => {
1030                StatusCode::InvalidArguments
1031            }
1032            Error::ColumnDefaultValue { source, .. } => source.status_code(),
1033            Error::EmptyDdlExpr { .. }
1034            | Error::InvalidPartitionRule { .. }
1035            | Error::ParseSqlValue { .. }
1036            | Error::InvalidTimestampRange { .. } => StatusCode::InvalidArguments,
1037            Error::CreateLogicalTables { .. } => StatusCode::Unexpected,
1038            Error::BuildRecordBatch { source, .. } => source.status_code(),
1039            Error::UpgradeCatalogManagerRef { .. } => StatusCode::Internal,
1040            Error::ColumnOptions { source, .. } => source.status_code(),
1041            Error::DecodeFlightData { source, .. } => source.status_code(),
1042            Error::ComputeArrow { .. } => StatusCode::Internal,
1043            Error::InvalidTimeIndexType { .. } | Error::InvalidTimezone { .. } => {
1044                StatusCode::InvalidArguments
1045            }
1046            Error::InvalidProcessId { .. } => StatusCode::InvalidArguments,
1047            Error::ProcessManagerMissing { .. } => StatusCode::Unexpected,
1048            Error::PathNotFound { .. } => StatusCode::InvalidArguments,
1049            Error::TimestampFormatNotSupported { .. } => StatusCode::InvalidArguments,
1050            Error::SqlCommon { source, .. } => source.status_code(),
1051            #[cfg(feature = "enterprise")]
1052            Error::InvalidTriggerName { .. } => StatusCode::InvalidArguments,
1053            #[cfg(feature = "enterprise")]
1054            Error::TooLargeDuration { .. } => StatusCode::InvalidArguments,
1055            #[cfg(feature = "enterprise")]
1056            Error::MissingTriggerQuerier { .. } => StatusCode::Internal,
1057            #[cfg(feature = "enterprise")]
1058            Error::TriggerQuerier { source, .. } => source.status_code(),
1059        }
1060    }
1061
1062    fn as_any(&self) -> &dyn Any {
1063        self
1064    }
1065}
1066
1067define_into_tonic_status!(Error);