databend_common_ast/ast/statements/
virtual_column.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;
20
21use crate::ast::write_dot_separated_list;
22use crate::ast::Identifier;
23use crate::ast::ShowLimit;
24
25#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
26pub struct RefreshVirtualColumnStmt {
27    pub catalog: Option<Identifier>,
28    pub database: Option<Identifier>,
29    pub table: Identifier,
30}
31
32impl Display for RefreshVirtualColumnStmt {
33    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
34        write!(f, "REFRESH VIRTUAL COLUMN FOR ")?;
35        write_dot_separated_list(
36            f,
37            self.catalog
38                .iter()
39                .chain(&self.database)
40                .chain(Some(&self.table)),
41        )?;
42
43        Ok(())
44    }
45}
46
47#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
48pub struct ShowVirtualColumnsStmt {
49    pub catalog: Option<Identifier>,
50    pub database: Option<Identifier>,
51    pub table: Option<Identifier>,
52    pub limit: Option<ShowLimit>,
53}
54
55impl Display for ShowVirtualColumnsStmt {
56    fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
57        write!(f, "SHOW VIRTUAL COLUMNS")?;
58        if let Some(table) = &self.table {
59            write!(f, " FROM {}", table)?;
60        }
61        if let Some(database) = &self.database {
62            write!(f, " FROM ")?;
63            if let Some(catalog) = &self.catalog {
64                write!(f, "{catalog}.",)?;
65            }
66            write!(f, "{database}")?;
67        }
68
69        if let Some(limit) = &self.limit {
70            write!(f, " {limit}")?;
71        }
72
73        Ok(())
74    }
75}