cql3_parser/
create_materialized_view.rs1use crate::common::{FQName, Identifier, PrimaryKey};
2use crate::common::{RelationElement, WithItem};
3use itertools::Itertools;
4use std::fmt::{Display, Formatter};
5
6#[derive(PartialEq, Debug, Clone)]
8pub struct CreateMaterializedView {
9 pub if_not_exists: bool,
11 pub name: FQName,
13 pub columns: Vec<Identifier>,
15 pub table: FQName,
17 pub where_clause: Vec<RelationElement>,
20 pub key: PrimaryKey,
22 pub with_clause: Vec<WithItem>,
24}
25
26impl Display for CreateMaterializedView {
27 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28 write!(
29 f,
30 "CREATE MATERIALIZED VIEW {}{} AS SELECT {} FROM {} WHERE {} {}{}",
31 if self.if_not_exists {
32 "IF NOT EXISTS "
33 } else {
34 ""
35 },
36 self.name,
37 self.columns.iter().map(|c| c.to_string()).join(", "),
38 self.table,
39 self.where_clause.iter().join(" AND "),
40 self.key,
41 if self.with_clause.is_empty() {
42 "".to_string()
43 } else {
44 format!(
45 " WITH {}",
46 self.with_clause.iter().map(|x| x.to_string()).join(" AND ")
47 )
48 }
49 )
50 }
51}