databend_common_ast/ast/statements/
virtual_column.rs1use 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}