databend_common_ast/ast/statements/
catalog.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::collections::BTreeMap;
16use std::fmt::Display;
17use std::fmt::Formatter;
18
19use derive_visitor::Drive;
20use derive_visitor::DriveMut;
21
22use crate::ast::write_comma_separated_string_map;
23use crate::ast::CatalogType;
24use crate::ast::Identifier;
25use crate::ast::ShowLimit;
26
27#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
28pub struct ShowCatalogsStmt {
29    pub limit: Option<ShowLimit>,
30}
31
32impl Display for ShowCatalogsStmt {
33    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
34        write!(f, "SHOW CATALOGS")?;
35        if let Some(limit) = &self.limit {
36            write!(f, " {}", limit)?
37        }
38
39        Ok(())
40    }
41}
42
43#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
44pub struct ShowCreateCatalogStmt {
45    pub catalog: Identifier,
46}
47
48impl Display for ShowCreateCatalogStmt {
49    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
50        write!(f, "SHOW CREATE CATALOG {}", &self.catalog)
51    }
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
55pub struct CreateCatalogStmt {
56    pub if_not_exists: bool,
57    pub catalog_name: String,
58    pub catalog_type: CatalogType,
59    pub catalog_options: BTreeMap<String, String>,
60}
61
62impl Display for CreateCatalogStmt {
63    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
64        write!(f, "CREATE CATALOG")?;
65        if self.if_not_exists {
66            write!(f, " IF NOT EXISTS")?;
67        }
68        write!(f, " {}", self.catalog_name)?;
69        write!(f, " TYPE={}", self.catalog_type)?;
70        write!(f, " CONNECTION = ( ")?;
71        write_comma_separated_string_map(f, &self.catalog_options)?;
72        write!(f, " )")
73    }
74}
75
76#[derive(Debug, Clone, PartialEq, Eq, Drive, DriveMut)]
77pub struct DropCatalogStmt {
78    pub if_exists: bool,
79    pub catalog: Identifier,
80}
81
82impl Display for DropCatalogStmt {
83    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
84        write!(f, "DROP CATALOG ")?;
85        if self.if_exists {
86            write!(f, "IF EXISTS ")?;
87        }
88        write!(f, "{}", self.catalog)
89    }
90}