1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::common::{ColumnDefinition, FQName, Identifier, WithItem};
use itertools::Itertools;
use std::fmt::{Display, Formatter};
#[derive(PartialEq, Debug, Clone)]
pub struct AlterTable {
pub name: FQName,
pub operation: AlterTableOperation,
}
#[derive(PartialEq, Debug, Clone)]
pub enum AlterTableOperation {
Add(Vec<ColumnDefinition>),
DropColumns(Vec<Identifier>),
DropCompactStorage,
Rename((Identifier, Identifier)),
With(Vec<WithItem>),
}
impl Display for AlterTableOperation {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
AlterTableOperation::Add(columns) => write!(
f,
"ADD {}",
columns.iter().map(|x| x.to_string()).join(", ")
),
AlterTableOperation::DropColumns(columns) => write!(
f,
"DROP {}",
columns.iter().map(|c| c.to_string()).join(", ")
),
AlterTableOperation::DropCompactStorage => write!(f, "DROP COMPACT STORAGE"),
AlterTableOperation::Rename((from, to)) => write!(f, "RENAME {} TO {}", from, to),
AlterTableOperation::With(with_element) => write!(
f,
"WITH {}",
with_element.iter().map(|x| x.to_string()).join(" AND ")
),
}
}
}