Skip to main content

databend_common_ast/ast/statements/
statement.rs

1// Copyright 2021 Datafuse Labs
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::fmt::Display;
16use std::fmt::Formatter;
17
18use derive_visitor::Drive;
19use derive_visitor::DriveMut;
20use dictionary::CreateDictionaryStmt;
21use dictionary::DropDictionaryStmt;
22use dictionary::ShowCreateDictionaryStmt;
23use itertools::Itertools;
24
25use super::merge_into::MergeIntoStmt;
26use super::*;
27use crate::Span;
28use crate::ast::CreateOption;
29use crate::ast::Identifier;
30use crate::ast::Query;
31use crate::ast::quote::QuotedString;
32use crate::ast::statements::connection::CreateConnectionStmt;
33use crate::ast::statements::pipe::CreatePipeStmt;
34use crate::ast::statements::role::AlterRoleStmt;
35use crate::ast::statements::settings::Settings;
36use crate::ast::statements::task::CreateTaskStmt;
37use crate::ast::statements::warehouse::ShowWarehousesStmt;
38use crate::ast::statements::worker::ShowWorkersStmt;
39use crate::ast::statements::workload::CreateWorkloadGroupStmt;
40use crate::ast::statements::workload::DropWorkloadGroupStmt;
41use crate::ast::statements::workload::RenameWorkloadGroupStmt;
42use crate::ast::statements::workload::SetWorkloadGroupQuotasStmt;
43use crate::ast::statements::workload::ShowWorkloadGroupsStmt;
44use crate::ast::write_comma_separated_list;
45
46// SQL statement
47#[allow(clippy::large_enum_variant)]
48#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
49pub enum Statement {
50    Query(Box<Query>),
51    StatementWithSettings {
52        settings: Option<Settings>,
53        stmt: Box<Statement>,
54    },
55    Explain {
56        kind: ExplainKind,
57        options: (Span, Vec<ExplainOption>),
58        query: Box<Statement>,
59    },
60    ExplainAnalyze {
61        // if partial is true, only scan/filter/join will be shown.
62        partial: bool,
63        graphical: bool,
64        query: Box<Statement>,
65    },
66    ReportIssue(String),
67
68    CopyIntoTable(CopyIntoTableStmt),
69    CopyIntoLocation(CopyIntoLocationStmt),
70
71    Call(CallStmt),
72
73    ShowSettings {
74        show_options: Option<ShowOptions>,
75    },
76    ShowProcessList {
77        show_options: Option<ShowOptions>,
78    },
79    ShowMetrics {
80        show_options: Option<ShowOptions>,
81    },
82    ShowEngines {
83        show_options: Option<ShowOptions>,
84    },
85    ShowFunctions {
86        show_options: Option<ShowOptions>,
87    },
88    ShowUserFunctions {
89        show_options: Option<ShowOptions>,
90    },
91    ShowTableFunctions {
92        show_options: Option<ShowOptions>,
93    },
94    ShowIndexes {
95        show_options: Option<ShowOptions>,
96    },
97    ShowLocks(ShowLocksStmt),
98
99    KillStmt {
100        kill_target: KillTarget,
101        object_id: String,
102    },
103
104    SetStmt {
105        settings: Settings,
106    },
107    UnSetStmt {
108        settings: Settings,
109    },
110
111    ShowVariables {
112        show_options: Option<ShowOptions>,
113    },
114
115    SetRole {
116        is_default: bool,
117        role_name: String,
118    },
119
120    SetSecondaryRoles {
121        option: SecondaryRolesOption,
122    },
123
124    Insert(InsertStmt),
125    InsertMultiTable(InsertMultiTableStmt),
126    Replace(ReplaceStmt),
127    MergeInto(MergeIntoStmt),
128    Delete(DeleteStmt),
129
130    Update(UpdateStmt),
131
132    // Catalogs
133    ShowCatalogs(ShowCatalogsStmt),
134    ShowCreateCatalog(ShowCreateCatalogStmt),
135    CreateCatalog(CreateCatalogStmt),
136    DropCatalog(DropCatalogStmt),
137    UseCatalog {
138        catalog: Identifier,
139    },
140
141    // Warehouses
142    ShowOnlineNodes(ShowOnlineNodesStmt),
143    UseWarehouse(UseWarehouseStmt),
144    ShowWarehouses(ShowWarehousesStmt),
145    DropWarehouse(DropWarehouseStmt),
146    CreateWarehouse(CreateWarehouseStmt),
147    RenameWarehouse(RenameWarehouseStmt),
148    ResumeWarehouse(ResumeWarehouseStmt),
149    SuspendWarehouse(SuspendWarehouseStmt),
150    InspectWarehouse(InspectWarehouseStmt),
151    AddWarehouseCluster(AddWarehouseClusterStmt),
152    DropWarehouseCluster(DropWarehouseClusterStmt),
153    RenameWarehouseCluster(RenameWarehouseClusterStmt),
154    AssignWarehouseNodes(AssignWarehouseNodesStmt),
155    UnassignWarehouseNodes(UnassignWarehouseNodesStmt),
156
157    // Workers
158    ShowWorkers(ShowWorkersStmt),
159    CreateWorker(CreateWorkerStmt),
160    AlterWorker(AlterWorkerStmt),
161    DropWorker(DropWorkerStmt),
162
163    // Workloads
164    ShowWorkloadGroups(ShowWorkloadGroupsStmt),
165    CreateWorkloadGroup(CreateWorkloadGroupStmt),
166    DropWorkloadGroup(DropWorkloadGroupStmt),
167    RenameWorkloadGroup(RenameWorkloadGroupStmt),
168    SetWorkloadQuotasGroup(SetWorkloadGroupQuotasStmt),
169    UnsetWorkloadQuotasGroup(UnsetWorkloadGroupQuotasStmt),
170
171    // Databases
172    ShowDatabases(ShowDatabasesStmt),
173    ShowDropDatabases(ShowDropDatabasesStmt),
174    ShowCreateDatabase(ShowCreateDatabaseStmt),
175    CreateDatabase(CreateDatabaseStmt),
176    DropDatabase(DropDatabaseStmt),
177    UndropDatabase(UndropDatabaseStmt),
178    AlterDatabase(AlterDatabaseStmt),
179    UseDatabase {
180        database: Identifier,
181    },
182
183    // Tables
184    ShowTables(ShowTablesStmt),
185    ShowCreateTable(ShowCreateTableStmt),
186    DescribeTable(DescribeTableStmt),
187    ShowTablesStatus(ShowTablesStatusStmt),
188    ShowDropTables(ShowDropTablesStmt),
189    AttachTable(AttachTableStmt),
190    CreateTable(CreateTableStmt),
191    DropTable(DropTableStmt),
192    UndropTable(UndropTableStmt),
193    AlterTable(AlterTableStmt),
194    RenameTable(RenameTableStmt),
195    TruncateTable(TruncateTableStmt),
196    OptimizeTable(OptimizeTableStmt),
197    VacuumTable(VacuumTableStmt),
198    VacuumDropTable(VacuumDropTableStmt),
199    VacuumTemporaryFiles(VacuumTemporaryFiles),
200    VacuumVirtualColumn(VacuumVirtualColumnStmt),
201    AnalyzeTable(AnalyzeTableStmt),
202    ExistsTable(ExistsTableStmt),
203    ShowStatistics(ShowStatisticsStmt),
204
205    // Dictionaries
206    CreateDictionary(CreateDictionaryStmt),
207    DropDictionary(DropDictionaryStmt),
208    ShowCreateDictionary(ShowCreateDictionaryStmt),
209    ShowDictionaries(ShowDictionariesStmt),
210    RenameDictionary(RenameDictionaryStmt),
211
212    // Columns
213    ShowColumns(ShowColumnsStmt),
214
215    // Views
216    CreateView(CreateViewStmt),
217    AlterView(AlterViewStmt),
218    DropView(DropViewStmt),
219    ShowViews(ShowViewsStmt),
220    DescribeView(DescribeViewStmt),
221
222    // Streams
223    CreateStream(CreateStreamStmt),
224    DropStream(DropStreamStmt),
225    ShowStreams(ShowStreamsStmt),
226    DescribeStream(DescribeStreamStmt),
227
228    // Indexes
229    CreateIndex(CreateIndexStmt),
230    DropIndex(DropIndexStmt),
231    RefreshIndex(RefreshIndexStmt),
232    CreateTableIndex(CreateTableIndexStmt),
233    DropTableIndex(DropTableIndexStmt),
234    RefreshTableIndex(RefreshTableIndexStmt),
235
236    // VirtualColumns
237    RefreshVirtualColumn(RefreshVirtualColumnStmt),
238    ShowVirtualColumns(ShowVirtualColumnsStmt),
239
240    // User
241    ShowUsers {
242        show_options: Option<ShowOptions>,
243    },
244    DescribeUser {
245        user: UserIdentity,
246    },
247    CreateUser(CreateUserStmt),
248    AlterUser(AlterUserStmt),
249    DropUser {
250        if_exists: bool,
251        user: UserIdentity,
252    },
253    ShowRoles {
254        show_options: Option<ShowOptions>,
255    },
256    CreateRole {
257        create_option: CreateOption,
258        role_name: String,
259        comment: Option<String>,
260    },
261    DropRole {
262        if_exists: bool,
263        role_name: String,
264    },
265    AlterRole(AlterRoleStmt),
266    Grant(GrantStmt),
267    ShowGrants {
268        principal: Option<PrincipalIdentity>,
269        show_options: Option<ShowOptions>,
270    },
271    ShowObjectPrivileges(ShowObjectPrivilegesStmt),
272    ShowGrantsOfRole(ShowGranteesOfRoleStmt),
273    Revoke(RevokeStmt),
274
275    // UDF
276    CreateUDF(CreateUDFStmt),
277    DropUDF {
278        if_exists: bool,
279        udf_name: Identifier,
280    },
281    AlterUDF(AlterUDFStmt),
282
283    // RowAccessPolicy
284    CreateRowAccessPolicy(CreateRowAccessPolicyStmt),
285    DropRowAccessPolicy(DropRowAccessPolicyStmt),
286    DescRowAccessPolicy(DescRowAccessPolicyStmt),
287
288    // Tags
289    CreateTag(CreateTagStmt),
290    DropTag(DropTagStmt),
291    ShowTags(ShowTagsStmt),
292    AlterObjectTag(AlterObjectTagStmt),
293
294    // Stages
295    CreateStage(CreateStageStmt),
296    AlterStage(AlterStageStmt),
297    ShowStages {
298        show_options: Option<ShowOptions>,
299    },
300    DropStage {
301        if_exists: bool,
302        stage_name: String,
303    },
304    DescribeStage {
305        stage_name: String,
306    },
307    RemoveStage {
308        location: String,
309        pattern: String,
310    },
311    ListStage {
312        location: String,
313        pattern: Option<String>,
314    },
315    // Connection
316    CreateConnection(CreateConnectionStmt),
317    DropConnection(DropConnectionStmt),
318    DescribeConnection(DescribeConnectionStmt),
319    ShowConnections(ShowConnectionsStmt),
320
321    // UserDefinedFileFormat
322    CreateFileFormat {
323        create_option: CreateOption,
324        name: String,
325        file_format_options: FileFormatOptions,
326    },
327    DropFileFormat {
328        if_exists: bool,
329        name: String,
330    },
331    ShowFileFormats,
332    Presign(PresignStmt),
333
334    // data mask
335    CreateDatamaskPolicy(CreateDatamaskPolicyStmt),
336    DropDatamaskPolicy(DropDatamaskPolicyStmt),
337    DescDatamaskPolicy(DescDatamaskPolicyStmt),
338
339    // network policy
340    CreateNetworkPolicy(CreateNetworkPolicyStmt),
341    AlterNetworkPolicy(AlterNetworkPolicyStmt),
342    DropNetworkPolicy(DropNetworkPolicyStmt),
343    DescNetworkPolicy(DescNetworkPolicyStmt),
344    ShowNetworkPolicies,
345
346    // password policy
347    CreatePasswordPolicy(CreatePasswordPolicyStmt),
348    AlterPasswordPolicy(AlterPasswordPolicyStmt),
349    DropPasswordPolicy(DropPasswordPolicyStmt),
350    DescPasswordPolicy(DescPasswordPolicyStmt),
351    ShowPasswordPolicies {
352        show_options: Option<ShowOptions>,
353    },
354
355    // tasks
356    CreateTask(CreateTaskStmt),
357    AlterTask(AlterTaskStmt),
358    ExecuteTask(ExecuteTaskStmt),
359    DescribeTask(DescribeTaskStmt),
360    DropTask(DropTaskStmt),
361    ShowTasks(ShowTasksStmt),
362
363    CreateDynamicTable(CreateDynamicTableStmt),
364
365    // pipes
366    CreatePipe(CreatePipeStmt),
367    DescribePipe(DescribePipeStmt),
368    DropPipe(DropPipeStmt),
369    AlterPipe(AlterPipeStmt),
370
371    // Transactions
372    Begin,
373    Commit,
374    Abort,
375
376    // Notifications
377    CreateNotification(CreateNotificationStmt),
378    AlterNotification(AlterNotificationStmt),
379    DropNotification(DropNotificationStmt),
380    DescribeNotification(DescribeNotificationStmt),
381
382    // Stored procedures
383    ExecuteImmediate(ExecuteImmediateStmt),
384    CreateProcedure(CreateProcedureStmt),
385    DropProcedure(DropProcedureStmt),
386    ShowProcedures {
387        show_options: Option<ShowOptions>,
388    },
389    DescProcedure(DescProcedureStmt),
390    CallProcedure(CallProcedureStmt),
391
392    // Sequence
393    CreateSequence(CreateSequenceStmt),
394    DropSequence(DropSequenceStmt),
395    ShowSequences {
396        show_options: Option<ShowOptions>,
397    },
398    DescSequence {
399        name: Identifier,
400    },
401
402    // Set priority for query
403    SetPriority {
404        priority: Priority,
405        object_id: String,
406    },
407
408    // System actions
409    System(SystemStmt),
410}
411
412impl Statement {
413    pub fn to_mask_sql(&self) -> String {
414        match self {
415            Statement::CopyIntoTable(copy) => {
416                let mut copy_clone = copy.clone();
417
418                if let CopyIntoTableSource::Location(FileLocation::Uri(location)) =
419                    &mut copy_clone.src
420                {
421                    location.connection = location.connection.mask()
422                }
423                format!("{}", Statement::CopyIntoTable(copy_clone))
424            }
425            Statement::CopyIntoLocation(copy) => {
426                let mut copy_clone = copy.clone();
427
428                if let FileLocation::Uri(location) = &mut copy_clone.dst {
429                    location.connection = location.connection.mask()
430                }
431                format!("{}", Statement::CopyIntoLocation(copy_clone))
432            }
433            Statement::CreateStage(stage) => {
434                let mut stage_clone = stage.clone();
435                if let Some(location) = &mut stage_clone.location {
436                    location.connection = location.connection.mask()
437                }
438                format!("{}", Statement::CreateStage(stage_clone))
439            }
440            Statement::AlterStage(stage) => {
441                let mut stage_clone = stage.clone();
442                if let AlterStageAction::Set(options) = &mut stage_clone.action
443                    && let Some(location) = &mut options.location
444                {
445                    location.connection = location.connection.mask();
446                }
447                format!("{}", Statement::AlterStage(stage_clone))
448            }
449            Statement::AttachTable(attach) => {
450                let mut attach_clone = attach.clone();
451                attach_clone.uri_location.connection = attach_clone.uri_location.connection.mask();
452                format!("{}", Statement::AttachTable(attach_clone))
453            }
454            _ => format!("{}", self),
455        }
456    }
457
458    pub fn allowed_in_multi_statement(&self) -> bool {
459        match self {
460            Statement::Query(..)
461            | Statement::Explain { .. }
462            | Statement::ReportIssue { .. }
463            | Statement::ExplainAnalyze { .. }
464            | Statement::CopyIntoTable(..)
465            | Statement::CopyIntoLocation(..)
466            | Statement::Call(..)
467            | Statement::ShowSettings { .. }
468            | Statement::ShowProcessList { .. }
469            | Statement::ShowMetrics { .. }
470            | Statement::ShowEngines { .. }
471            | Statement::ShowFunctions { .. }
472            | Statement::ShowUserFunctions { .. }
473            | Statement::ShowTableFunctions { .. }
474            | Statement::ShowIndexes { .. }
475            | Statement::ShowLocks(..)
476            | Statement::SetPriority { .. }
477            | Statement::System(..)
478            | Statement::KillStmt { .. }
479            | Statement::SetStmt { .. }
480            | Statement::UnSetStmt { .. }
481            | Statement::ShowVariables { .. }
482            | Statement::SetRole { .. }
483            | Statement::SetSecondaryRoles { .. }
484            | Statement::Insert(..)
485            | Statement::InsertMultiTable(..)
486            | Statement::Replace(..)
487            | Statement::MergeInto(..)
488            | Statement::Delete(..)
489            | Statement::Update(..)
490            | Statement::ShowCatalogs(..)
491            | Statement::ShowCreateCatalog(..)
492            | Statement::UseCatalog { .. }
493            | Statement::ShowDatabases(..)
494            | Statement::ShowDropDatabases(..)
495            | Statement::ShowCreateDatabase(..)
496            | Statement::UseDatabase { .. }
497            | Statement::ShowTables(..)
498            | Statement::ShowCreateTable(..)
499            | Statement::DescribeTable(..)
500            | Statement::ShowStatistics(..)
501            | Statement::ShowTablesStatus(..)
502            | Statement::ShowDropTables(..)
503            | Statement::OptimizeTable(..)
504            | Statement::VacuumTable(..)
505            | Statement::VacuumDropTable(..)
506            | Statement::VacuumTemporaryFiles(..)
507            | Statement::VacuumVirtualColumn(..)
508            | Statement::AnalyzeTable(..)
509            | Statement::ExistsTable(..)
510            | Statement::ShowCreateDictionary(..)
511            | Statement::ShowDictionaries(..)
512            | Statement::ShowColumns(..)
513            | Statement::ShowViews(..)
514            | Statement::DescribeView(..)
515            | Statement::ShowStreams(..)
516            | Statement::DescribeStream(..)
517            | Statement::RefreshIndex(..)
518            | Statement::RefreshTableIndex(..)
519            | Statement::RefreshVirtualColumn(..)
520            | Statement::ShowVirtualColumns(..)
521            | Statement::ShowUsers { .. }
522            | Statement::DescribeUser { .. }
523            | Statement::ShowRoles { .. }
524            | Statement::ShowGrants { .. }
525            | Statement::ShowObjectPrivileges(..)
526            | Statement::ShowGrantsOfRole(..)
527            | Statement::ShowTags(..)
528            | Statement::ShowStages { .. }
529            | Statement::DescribeStage { .. }
530            | Statement::RemoveStage { .. }
531            | Statement::ListStage { .. }
532            | Statement::DescribeConnection(..)
533            | Statement::ShowConnections(..)
534            | Statement::ShowFileFormats
535            | Statement::Presign(..)
536            | Statement::DescDatamaskPolicy(..)
537            | Statement::DescRowAccessPolicy(..)
538            | Statement::DescNetworkPolicy(..)
539            | Statement::ShowNetworkPolicies
540            | Statement::DescPasswordPolicy(..)
541            | Statement::ShowPasswordPolicies { .. }
542            | Statement::ExecuteTask(..)
543            | Statement::DescribeTask(..)
544            | Statement::ShowTasks(..)
545            | Statement::DescribePipe(..)
546            | Statement::Begin
547            | Statement::Commit
548            | Statement::Abort
549            | Statement::DescribeNotification(..)
550            | Statement::ExecuteImmediate(..)
551            | Statement::ShowProcedures { .. }
552            | Statement::ShowSequences { .. }
553            | Statement::DescSequence { .. }
554            | Statement::DescProcedure(..)
555            | Statement::CallProcedure(..)
556            | Statement::ShowWarehouses(..)
557            | Statement::ShowWorkers(..)
558            | Statement::ShowOnlineNodes(..)
559            | Statement::InspectWarehouse(..) => true,
560
561            Statement::CreateDatabase(..)
562            | Statement::CreateTable(..)
563            | Statement::CreateView(..)
564            | Statement::CreateIndex(..)
565            | Statement::CreateStage(..)
566            | Statement::AlterStage(..)
567            | Statement::CreateSequence(..)
568            | Statement::CreateDictionary(..)
569            | Statement::CreateConnection(..)
570            | Statement::CreatePipe(..)
571            | Statement::AlterTable(..)
572            | Statement::AlterObjectTag(..)
573            | Statement::AlterView(..)
574            | Statement::AlterUser(..)
575            | Statement::AlterDatabase(..)
576            | Statement::DropDatabase(..)
577            | Statement::DropTable(..)
578            | Statement::DropView(..)
579            | Statement::DropIndex(..)
580            | Statement::DropSequence(..)
581            | Statement::DropDictionary(..)
582            | Statement::TruncateTable(..)
583            | Statement::AttachTable(..)
584            | Statement::RenameTable(..)
585            | Statement::CreateCatalog(..)
586            | Statement::DropCatalog(..)
587            | Statement::UndropDatabase(..)
588            | Statement::UndropTable(..)
589            | Statement::RenameDictionary(..)
590            | Statement::CreateStream(..)
591            | Statement::DropStream(..)
592            | Statement::CreateTableIndex(..)
593            | Statement::DropTableIndex(..)
594            | Statement::CreateUser(..)
595            | Statement::DropUser { .. }
596            | Statement::CreateRole { .. }
597            | Statement::DropRole { .. }
598            | Statement::Grant(..)
599            | Statement::Revoke(..)
600            | Statement::CreateUDF(..)
601            | Statement::DropUDF { .. }
602            | Statement::AlterUDF(..)
603            | Statement::CreateRowAccessPolicy(..)
604            | Statement::DropRowAccessPolicy(..)
605            | Statement::CreateTag(..)
606            | Statement::DropTag(..)
607            | Statement::DropStage { .. }
608            | Statement::DropConnection(..)
609            | Statement::CreateFileFormat { .. }
610            | Statement::DropFileFormat { .. }
611            | Statement::CreateDatamaskPolicy(..)
612            | Statement::DropDatamaskPolicy(..)
613            | Statement::CreateNetworkPolicy(..)
614            | Statement::AlterNetworkPolicy(..)
615            | Statement::DropNetworkPolicy(..)
616            | Statement::CreatePasswordPolicy(..)
617            | Statement::AlterPasswordPolicy(..)
618            | Statement::DropPasswordPolicy(..)
619            | Statement::CreateTask(..)
620            | Statement::AlterTask(..)
621            | Statement::DropTask(..)
622            | Statement::CreateDynamicTable(..)
623            | Statement::DropPipe(..)
624            | Statement::AlterPipe(..)
625            | Statement::CreateNotification(..)
626            | Statement::AlterNotification(..)
627            | Statement::DropNotification(..)
628            | Statement::CreateProcedure(..)
629            | Statement::DropProcedure(..)
630            | Statement::CreateWarehouse(..)
631            | Statement::UseWarehouse(..)
632            | Statement::DropWarehouse(..)
633            | Statement::RenameWarehouse(..)
634            | Statement::AddWarehouseCluster(..)
635            | Statement::DropWarehouseCluster(..)
636            | Statement::RenameWarehouseCluster(..)
637            | Statement::AssignWarehouseNodes(..)
638            | Statement::UnassignWarehouseNodes(..)
639            | Statement::ResumeWarehouse(..)
640            | Statement::SuspendWarehouse(..)
641            | Statement::CreateWorker(..)
642            | Statement::AlterWorker(..)
643            | Statement::DropWorker(..)
644            | Statement::ShowWorkloadGroups(..)
645            | Statement::CreateWorkloadGroup(..)
646            | Statement::DropWorkloadGroup(..)
647            | Statement::RenameWorkloadGroup(..)
648            | Statement::SetWorkloadQuotasGroup(..)
649            | Statement::UnsetWorkloadQuotasGroup(..) => false,
650            Statement::AlterRole(..) => false,
651            Statement::StatementWithSettings { stmt, settings: _ } => {
652                stmt.allowed_in_multi_statement()
653            }
654        }
655    }
656
657    pub fn is_transaction_command(&self) -> bool {
658        matches!(
659            self,
660            Statement::Commit | Statement::Abort | Statement::Begin
661        )
662    }
663}
664
665impl Display for Statement {
666    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
667        match self {
668            Statement::Explain {
669                options: (_, options),
670                kind,
671                query,
672            } => {
673                write!(f, "EXPLAIN")?;
674                if !options.is_empty() {
675                    write!(
676                        f,
677                        "({})",
678                        options
679                            .iter()
680                            .map(|opt| {
681                                match opt {
682                                    ExplainOption::Verbose => "VERBOSE",
683                                    ExplainOption::Logical => "LOGICAL",
684                                    ExplainOption::Optimized => "OPTIMIZED",
685                                    ExplainOption::Decorrelated => "DECORRELATED",
686                                }
687                            })
688                            .join(", ")
689                    )?;
690                }
691                match kind {
692                    ExplainKind::Ast(_) => write!(f, " AST")?,
693                    ExplainKind::Syntax(_) => write!(f, " SYNTAX")?,
694                    ExplainKind::Graph => write!(f, " GRAPH")?,
695                    ExplainKind::Pipeline => write!(f, " PIPELINE")?,
696                    ExplainKind::Fragments => write!(f, " FRAGMENTS")?,
697                    ExplainKind::Raw => write!(f, " RAW")?,
698                    ExplainKind::Optimized => write!(f, " Optimized")?,
699                    ExplainKind::Decorrelated => write!(f, " DECORRELATED")?,
700                    ExplainKind::Plan => (),
701                    ExplainKind::AnalyzePlan => write!(f, " ANALYZE")?,
702                    ExplainKind::Join => write!(f, " JOIN")?,
703                    ExplainKind::Memo(_) => write!(f, " MEMO")?,
704                    ExplainKind::Graphical => write!(f, " GRAPHICAL")?,
705                    ExplainKind::Perf { event_groups } => {
706                        write!(f, " PERF")?;
707                        if !event_groups.is_empty() {
708                            let groups_str: Vec<String> =
709                                event_groups.iter().map(|g| g.join("+")).collect();
710                            write!(f, "(events='{}')", groups_str.join(","))?;
711                        }
712                    }
713                }
714                write!(f, " {query}")?;
715            }
716            Statement::ReportIssue(sql) => {
717                write!(f, "REPORT ISSUE {}", sql)?;
718            }
719            Statement::StatementWithSettings { settings, stmt } => {
720                if let Some(setting) = settings {
721                    write!(f, "SETTINGS (")?;
722                    let ids = &setting.identifiers;
723                    if let SetValues::Expr(values) = &setting.values {
724                        let mut expr = Vec::with_capacity(ids.len());
725                        for (id, value) in ids.iter().zip(values.iter()) {
726                            expr.push(format!("{} = {}", id, value));
727                        }
728                        write_comma_separated_list(f, expr)?;
729                    } else {
730                        unreachable!();
731                    }
732                    write!(f, ") ")?;
733                } else {
734                    write!(f, "SETTINGS ")?;
735                }
736                write!(f, "{stmt}")?;
737            }
738            Statement::ExplainAnalyze {
739                partial,
740                graphical,
741                query,
742            } => {
743                if *partial {
744                    write!(f, "EXPLAIN ANALYZE PARTIAL {query}")?;
745                } else if *graphical {
746                    write!(f, "EXPLAIN ANALYZE GRAPHICAL {query}")?;
747                } else {
748                    write!(f, "EXPLAIN ANALYZE {query}")?;
749                }
750            }
751            Statement::Query(stmt) => write!(f, "{stmt}")?,
752            Statement::Insert(stmt) => write!(f, "{stmt}")?,
753            Statement::InsertMultiTable(insert_multi_table) => write!(f, "{insert_multi_table}")?,
754            Statement::Replace(stmt) => write!(f, "{stmt}")?,
755            Statement::MergeInto(stmt) => write!(f, "{stmt}")?,
756            Statement::Delete(stmt) => write!(f, "{stmt}")?,
757            Statement::Update(stmt) => write!(f, "{stmt}")?,
758            Statement::CopyIntoTable(stmt) => write!(f, "{stmt}")?,
759            Statement::CopyIntoLocation(stmt) => write!(f, "{stmt}")?,
760            Statement::ShowSettings { show_options } => {
761                write!(f, "SHOW SETTINGS")?;
762                if let Some(show_options) = show_options {
763                    write!(f, " {show_options}")?;
764                }
765            }
766            Statement::ShowVariables { show_options } => {
767                write!(f, "SHOW VARIABLES")?;
768                if let Some(show_options) = show_options {
769                    write!(f, " {show_options}")?;
770                }
771            }
772            Statement::ShowProcessList { show_options } => {
773                write!(f, "SHOW PROCESSLIST")?;
774                if let Some(show_options) = show_options {
775                    write!(f, " {show_options}")?;
776                }
777            }
778            Statement::ShowMetrics { show_options } => {
779                write!(f, "SHOW METRICS")?;
780                if let Some(show_options) = show_options {
781                    write!(f, " {show_options}")?;
782                }
783            }
784            Statement::ShowEngines { show_options } => {
785                write!(f, "SHOW ENGINES")?;
786                if let Some(show_options) = show_options {
787                    write!(f, " {show_options}")?;
788                }
789            }
790            Statement::ShowIndexes { show_options } => {
791                write!(f, "SHOW INDEXES")?;
792                if let Some(show_options) = show_options {
793                    write!(f, " {show_options}")?;
794                }
795            }
796            Statement::ShowFunctions { show_options } => {
797                write!(f, "SHOW FUNCTIONS")?;
798                if let Some(show_options) = show_options {
799                    write!(f, " {show_options}")?;
800                }
801            }
802            Statement::ShowUserFunctions { show_options } => {
803                write!(f, "SHOW USER FUNCTIONS")?;
804                if let Some(show_options) = show_options {
805                    write!(f, " {show_options}")?;
806                }
807            }
808            Statement::ShowTableFunctions { show_options } => {
809                write!(f, "SHOW TABLE_FUNCTIONS")?;
810                if let Some(show_options) = show_options {
811                    write!(f, " {show_options}")?;
812                }
813            }
814            Statement::ShowLocks(stmt) => write!(f, "{stmt}")?,
815            Statement::KillStmt {
816                kill_target,
817                object_id,
818            } => {
819                write!(f, "KILL")?;
820                match *kill_target {
821                    KillTarget::Query => write!(f, " QUERY")?,
822                    KillTarget::Connection => write!(f, " CONNECTION")?,
823                }
824                write!(f, " '{object_id}'")?;
825            }
826            Statement::SetStmt { settings } => write!(f, "SET {}", settings)?,
827            Statement::UnSetStmt { settings } => write!(f, "UNSET {}", settings)?,
828            Statement::SetRole {
829                is_default,
830                role_name,
831            } => {
832                write!(f, "SET ")?;
833                if *is_default {
834                    write!(f, "DEFAULT ")?;
835                }
836                write!(f, "ROLE '{role_name}'")?;
837            }
838            Statement::SetSecondaryRoles { option } => {
839                write!(f, "SET SECONDARY ROLES ")?;
840                match option {
841                    SecondaryRolesOption::None => write!(f, "NONE")?,
842                    SecondaryRolesOption::All => write!(f, "ALL")?,
843                    SecondaryRolesOption::SpecifyRole(roles) => {
844                        write_comma_separated_list(f, roles)?
845                    }
846                }
847            }
848            Statement::ShowCatalogs(stmt) => write!(f, "{stmt}")?,
849            Statement::ShowCreateCatalog(stmt) => write!(f, "{stmt}")?,
850            Statement::CreateCatalog(stmt) => write!(f, "{stmt}")?,
851            Statement::DropCatalog(stmt) => write!(f, "{stmt}")?,
852            Statement::UseCatalog { catalog } => write!(f, "USE CATALOG {catalog}")?,
853            Statement::ShowDatabases(stmt) => write!(f, "{stmt}")?,
854            Statement::ShowDropDatabases(stmt) => write!(f, "{stmt}")?,
855            Statement::ShowCreateDatabase(stmt) => write!(f, "{stmt}")?,
856            Statement::CreateDatabase(stmt) => write!(f, "{stmt}")?,
857            Statement::DropDatabase(stmt) => write!(f, "{stmt}")?,
858            Statement::UndropDatabase(stmt) => write!(f, "{stmt}")?,
859            Statement::AlterDatabase(stmt) => write!(f, "{stmt}")?,
860            Statement::UseDatabase { database } => write!(f, "USE {database}")?,
861            Statement::ShowTables(stmt) => write!(f, "{stmt}")?,
862            Statement::ShowColumns(stmt) => write!(f, "{stmt}")?,
863            Statement::ShowCreateTable(stmt) => write!(f, "{stmt}")?,
864            Statement::DescribeTable(stmt) => write!(f, "{stmt}")?,
865            Statement::ShowTablesStatus(stmt) => write!(f, "{stmt}")?,
866            Statement::ShowDropTables(stmt) => write!(f, "{stmt}")?,
867            Statement::ShowStatistics(stmt) => write!(f, "{stmt}")?,
868            Statement::AttachTable(stmt) => write!(f, "{stmt}")?,
869            Statement::CreateTable(stmt) => write!(f, "{stmt}")?,
870            Statement::DropTable(stmt) => write!(f, "{stmt}")?,
871            Statement::UndropTable(stmt) => write!(f, "{stmt}")?,
872            Statement::AlterTable(stmt) => write!(f, "{stmt}")?,
873            Statement::RenameTable(stmt) => write!(f, "{stmt}")?,
874            Statement::TruncateTable(stmt) => write!(f, "{stmt}")?,
875            Statement::OptimizeTable(stmt) => write!(f, "{stmt}")?,
876            Statement::VacuumTable(stmt) => write!(f, "{stmt}")?,
877            Statement::VacuumDropTable(stmt) => write!(f, "{stmt}")?,
878            Statement::VacuumTemporaryFiles(stmt) => write!(f, "{stmt}")?,
879            Statement::VacuumVirtualColumn(stmt) => write!(f, "{stmt}")?,
880            Statement::AnalyzeTable(stmt) => write!(f, "{stmt}")?,
881            Statement::ExistsTable(stmt) => write!(f, "{stmt}")?,
882            Statement::CreateDictionary(stmt) => write!(f, "{stmt}")?,
883            Statement::DropDictionary(stmt) => write!(f, "{stmt}")?,
884            Statement::ShowCreateDictionary(stmt) => write!(f, "{stmt}")?,
885            Statement::ShowDictionaries(stmt) => write!(f, "{stmt}")?,
886            Statement::RenameDictionary(stmt) => write!(f, "{stmt}")?,
887            Statement::CreateView(stmt) => write!(f, "{stmt}")?,
888            Statement::AlterView(stmt) => write!(f, "{stmt}")?,
889            Statement::DropView(stmt) => write!(f, "{stmt}")?,
890            Statement::ShowViews(stmt) => write!(f, "{stmt}")?,
891            Statement::DescribeView(stmt) => write!(f, "{stmt}")?,
892            Statement::CreateStream(stmt) => write!(f, "{stmt}")?,
893            Statement::DropStream(stmt) => write!(f, "{stmt}")?,
894            Statement::ShowStreams(stmt) => write!(f, "{stmt}")?,
895            Statement::DescribeStream(stmt) => write!(f, "{stmt}")?,
896            Statement::CreateIndex(stmt) => write!(f, "{stmt}")?,
897            Statement::DropIndex(stmt) => write!(f, "{stmt}")?,
898            Statement::RefreshIndex(stmt) => write!(f, "{stmt}")?,
899            Statement::CreateTableIndex(stmt) => write!(f, "{stmt}")?,
900            Statement::DropTableIndex(stmt) => write!(f, "{stmt}")?,
901            Statement::RefreshTableIndex(stmt) => write!(f, "{stmt}")?,
902            Statement::RefreshVirtualColumn(stmt) => write!(f, "{stmt}")?,
903            Statement::ShowVirtualColumns(stmt) => write!(f, "{stmt}")?,
904            Statement::ShowUsers { show_options } => {
905                write!(f, "SHOW USERS")?;
906                if let Some(show_options) = show_options {
907                    write!(f, " {show_options}")?;
908                }
909            }
910            Statement::DescribeUser { user } => write!(f, "DESCRIBE USER {user}")?,
911            Statement::ShowRoles { show_options } => {
912                write!(f, "SHOW ROLES")?;
913                if let Some(show_options) = show_options {
914                    write!(f, " {show_options}")?;
915                }
916            }
917            Statement::CreateUser(stmt) => write!(f, "{stmt}")?,
918            Statement::AlterUser(stmt) => write!(f, "{stmt}")?,
919            Statement::DropUser { if_exists, user } => {
920                write!(f, "DROP USER")?;
921                if *if_exists {
922                    write!(f, " IF EXISTS")?;
923                }
924                write!(f, " {}", user)?;
925            }
926            Statement::CreateRole {
927                create_option,
928                role_name: role,
929                comment,
930            } => {
931                write!(f, "CREATE")?;
932                if let CreateOption::CreateOrReplace = create_option {
933                    write!(f, " OR REPLACE")?;
934                }
935                write!(f, " ROLE")?;
936                if let CreateOption::CreateIfNotExists = create_option {
937                    write!(f, " IF NOT EXISTS")?;
938                }
939                write!(f, " {}", QuotedString(role, '\''))?;
940                if let Some(comment) = comment {
941                    write!(f, " COMMENT = '{comment}'")?;
942                }
943            }
944            Statement::DropRole {
945                if_exists,
946                role_name: role,
947            } => {
948                write!(f, "DROP ROLE")?;
949                if *if_exists {
950                    write!(f, " IF EXISTS")?;
951                }
952                write!(f, " '{role}'")?;
953            }
954            Statement::Grant(stmt) => write!(f, "{stmt}")?,
955            Statement::ShowGrants {
956                principal,
957                show_options,
958            } => {
959                write!(f, "SHOW GRANTS")?;
960                if let Some(principal) = principal {
961                    write!(f, " FOR")?;
962                    write!(f, "{principal}")?;
963                }
964                if let Some(show_options) = show_options {
965                    write!(f, " {show_options}")?;
966                }
967            }
968            Statement::ShowObjectPrivileges(stmt) => write!(f, "{stmt}")?,
969            Statement::ShowGrantsOfRole(stmt) => write!(f, "{stmt}")?,
970            Statement::Revoke(stmt) => write!(f, "{stmt}")?,
971            Statement::CreateUDF(stmt) => write!(f, "{stmt}")?,
972            Statement::DropUDF {
973                if_exists,
974                udf_name,
975            } => {
976                write!(f, "DROP FUNCTION")?;
977                if *if_exists {
978                    write!(f, " IF EXISTS")?;
979                }
980                write!(f, " {udf_name}")?;
981            }
982            Statement::AlterUDF(stmt) => write!(f, "{stmt}")?,
983            Statement::CreateRowAccessPolicy(stmt) => write!(f, "{stmt}")?,
984            Statement::DescRowAccessPolicy(stmt) => write!(f, "{stmt}")?,
985            Statement::DropRowAccessPolicy(stmt) => write!(f, "{stmt}")?,
986            Statement::CreateTag(stmt) => write!(f, "{stmt}")?,
987            Statement::DropTag(stmt) => write!(f, "{stmt}")?,
988            Statement::ShowTags(stmt) => write!(f, "{stmt}")?,
989            Statement::AlterObjectTag(stmt) => write!(f, "{stmt}")?,
990            Statement::ListStage { location, pattern } => {
991                write!(f, "LIST @{location}")?;
992                if let Some(pattern) = pattern {
993                    write!(f, " PATTERN = '{pattern}'")?;
994                }
995            }
996            Statement::ShowStages { show_options } => {
997                write!(f, "SHOW STAGES")?;
998                if let Some(show_options) = show_options {
999                    write!(f, " {show_options}")?;
1000                }
1001            }
1002            Statement::DropStage {
1003                if_exists,
1004                stage_name,
1005            } => {
1006                write!(f, "DROP STAGE")?;
1007                if *if_exists {
1008                    write!(f, " IF EXISTS")?;
1009                }
1010                write!(f, " {stage_name}")?;
1011            }
1012            Statement::CreateStage(stmt) => write!(f, "{stmt}")?,
1013            Statement::AlterStage(stmt) => write!(f, "{stmt}")?,
1014            Statement::RemoveStage { location, pattern } => {
1015                write!(f, "REMOVE @{location}")?;
1016                if !pattern.is_empty() {
1017                    write!(f, " PATTERN = '{pattern}'")?;
1018                }
1019            }
1020            Statement::DescribeStage { stage_name } => write!(f, "DESC STAGE {stage_name}")?,
1021            Statement::CreateFileFormat {
1022                create_option,
1023                name,
1024                file_format_options,
1025            } => {
1026                write!(f, "CREATE")?;
1027                if let CreateOption::CreateOrReplace = create_option {
1028                    write!(f, " OR REPLACE")?;
1029                }
1030                write!(f, " FILE FORMAT")?;
1031                if let CreateOption::CreateIfNotExists = create_option {
1032                    write!(f, " IF NOT EXISTS")?;
1033                }
1034                write!(f, " {name}")?;
1035                write!(f, " {file_format_options}")?;
1036            }
1037            Statement::DropFileFormat { if_exists, name } => {
1038                write!(f, "DROP FILE FORMAT")?;
1039                if *if_exists {
1040                    write!(f, " IF EXISTS")?;
1041                }
1042                write!(f, " {name}")?;
1043            }
1044            Statement::ShowFileFormats => write!(f, "SHOW FILE FORMATS")?,
1045            Statement::Call(stmt) => write!(f, "{stmt}")?,
1046            Statement::Presign(stmt) => write!(f, "{stmt}")?,
1047            Statement::CreateDatamaskPolicy(stmt) => write!(f, "{stmt}")?,
1048            Statement::DropDatamaskPolicy(stmt) => write!(f, "{stmt}")?,
1049            Statement::DescDatamaskPolicy(stmt) => write!(f, "{stmt}")?,
1050            Statement::CreateNetworkPolicy(stmt) => write!(f, "{stmt}")?,
1051            Statement::AlterNetworkPolicy(stmt) => write!(f, "{stmt}")?,
1052            Statement::DropNetworkPolicy(stmt) => write!(f, "{stmt}")?,
1053            Statement::DescNetworkPolicy(stmt) => write!(f, "{stmt}")?,
1054            Statement::ShowNetworkPolicies => write!(f, "SHOW NETWORK POLICIES")?,
1055            Statement::CreatePasswordPolicy(stmt) => write!(f, "{stmt}")?,
1056            Statement::AlterPasswordPolicy(stmt) => write!(f, "{stmt}")?,
1057            Statement::DropPasswordPolicy(stmt) => write!(f, "{stmt}")?,
1058            Statement::DescPasswordPolicy(stmt) => write!(f, "{stmt}")?,
1059            Statement::ShowPasswordPolicies { show_options } => {
1060                write!(f, "SHOW PASSWORD POLICIES")?;
1061                if let Some(show_options) = show_options {
1062                    write!(f, " {show_options}")?;
1063                }
1064            }
1065            Statement::CreateTask(stmt) => write!(f, "{stmt}")?,
1066            Statement::AlterTask(stmt) => write!(f, "{stmt}")?,
1067            Statement::ExecuteTask(stmt) => write!(f, "{stmt}")?,
1068            Statement::DropTask(stmt) => write!(f, "{stmt}")?,
1069            Statement::ShowTasks(stmt) => write!(f, "{stmt}")?,
1070            Statement::DescribeTask(stmt) => write!(f, "{stmt}")?,
1071            Statement::CreatePipe(stmt) => write!(f, "{stmt}")?,
1072            Statement::DescribePipe(stmt) => write!(f, "{stmt}")?,
1073            Statement::DropPipe(stmt) => write!(f, "{stmt}")?,
1074            Statement::AlterPipe(stmt) => write!(f, "{stmt}")?,
1075            Statement::CreateConnection(stmt) => write!(f, "{stmt}")?,
1076            Statement::DropConnection(stmt) => write!(f, "{stmt}")?,
1077            Statement::DescribeConnection(stmt) => write!(f, "{stmt}")?,
1078            Statement::ShowConnections(stmt) => write!(f, "{stmt}")?,
1079            Statement::Begin => write!(f, "BEGIN")?,
1080            Statement::Commit => write!(f, "COMMIT")?,
1081            Statement::Abort => write!(f, "ABORT")?,
1082            Statement::CreateNotification(stmt) => write!(f, "{stmt}")?,
1083            Statement::AlterNotification(stmt) => write!(f, "{stmt}")?,
1084            Statement::DropNotification(stmt) => write!(f, "{stmt}")?,
1085            Statement::DescribeNotification(stmt) => write!(f, "{stmt}")?,
1086            Statement::ExecuteImmediate(stmt) => write!(f, "{stmt}")?,
1087            Statement::CreateProcedure(stmt) => write!(f, "{stmt}")?,
1088            Statement::DropProcedure(stmt) => write!(f, "{stmt}")?,
1089            Statement::DescProcedure(stmt) => write!(f, "{stmt}")?,
1090            Statement::ShowProcedures { show_options } => {
1091                write!(f, "SHOW PROCEDURES")?;
1092                if let Some(show_options) = show_options {
1093                    write!(f, " {show_options}")?;
1094                }
1095            }
1096            Statement::CreateSequence(stmt) => write!(f, "{stmt}")?,
1097            Statement::DropSequence(stmt) => write!(f, "{stmt}")?,
1098            Statement::ShowSequences { show_options } => {
1099                write!(f, "SHOW SEQUENCES")?;
1100                if let Some(show_options) = show_options {
1101                    write!(f, " {show_options}")?;
1102                }
1103            }
1104            Statement::DescSequence { name } => {
1105                write!(f, "DESC SEQUENCE {name}")?;
1106            }
1107            Statement::CreateDynamicTable(stmt) => write!(f, "{stmt}")?,
1108            Statement::SetPriority {
1109                priority,
1110                object_id,
1111            } => {
1112                write!(f, "SET PRIORITY")?;
1113                write!(f, " {priority}")?;
1114                write!(f, " '{object_id}'")?;
1115            }
1116            Statement::System(stmt) => write!(f, "{stmt}")?,
1117            Statement::CallProcedure(stmt) => write!(f, "{stmt}")?,
1118
1119            Statement::ShowOnlineNodes(stmt) => write!(f, "{stmt}")?,
1120            Statement::ShowWarehouses(stmt) => write!(f, "{stmt}")?,
1121            Statement::UseWarehouse(stmt) => write!(f, "{stmt}")?,
1122            Statement::DropWarehouse(stmt) => write!(f, "{stmt}")?,
1123            Statement::CreateWarehouse(stmt) => write!(f, "{stmt}")?,
1124            Statement::RenameWarehouse(stmt) => write!(f, "{stmt}")?,
1125            Statement::ResumeWarehouse(stmt) => write!(f, "{stmt}")?,
1126            Statement::SuspendWarehouse(stmt) => write!(f, "{stmt}")?,
1127            Statement::InspectWarehouse(stmt) => write!(f, "{stmt}")?,
1128            Statement::AddWarehouseCluster(stmt) => write!(f, "{stmt}")?,
1129            Statement::DropWarehouseCluster(stmt) => write!(f, "{stmt}")?,
1130            Statement::RenameWarehouseCluster(stmt) => write!(f, "{stmt}")?,
1131            Statement::AssignWarehouseNodes(stmt) => write!(f, "{stmt}")?,
1132            Statement::UnassignWarehouseNodes(stmt) => write!(f, "{stmt}")?,
1133            Statement::ShowWorkers(stmt) => write!(f, "{stmt}")?,
1134            Statement::CreateWorker(stmt) => write!(f, "{stmt}")?,
1135            Statement::AlterWorker(stmt) => write!(f, "{stmt}")?,
1136            Statement::DropWorker(stmt) => write!(f, "{stmt}")?,
1137            Statement::ShowWorkloadGroups(stmt) => write!(f, "{stmt}")?,
1138            Statement::CreateWorkloadGroup(stmt) => write!(f, "{stmt}")?,
1139            Statement::DropWorkloadGroup(stmt) => write!(f, "{stmt}")?,
1140            Statement::RenameWorkloadGroup(stmt) => write!(f, "{stmt}")?,
1141            Statement::SetWorkloadQuotasGroup(stmt) => write!(f, "{stmt}")?,
1142            Statement::UnsetWorkloadQuotasGroup(stmt) => write!(f, "{stmt}")?,
1143            Statement::AlterRole(stmt) => write!(f, "{stmt}")?,
1144        }
1145        Ok(())
1146    }
1147}
1148
1149#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
1150pub struct StatementWithFormat {
1151    pub(crate) stmt: Statement,
1152    pub(crate) format: Option<String>,
1153}
1154
1155impl Display for StatementWithFormat {
1156    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
1157        write!(f, "{}", self.stmt)?;
1158        if let Some(format) = &self.format {
1159            write!(f, " FORMAT {}", format)?;
1160        }
1161        Ok(())
1162    }
1163}