MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / doc_create_table_from_source

Method doc_create_table_from_source

src/sql-pretty/src/doc.rs:234–309  ·  view source on GitHub ↗
(
        &'a self,
        v: &'a CreateTableFromSourceStatement<T>,
    )

Source from the content-addressed store, hash-verified

232 }
233
234 pub(crate) fn doc_create_table_from_source<'a, T: AstInfo>(
235 &'a self,
236 v: &'a CreateTableFromSourceStatement<T>,
237 ) -> RcDoc<'a> {
238 let mut docs = Vec::new();
239
240 // CREATE TABLE [IF NOT EXISTS] name
241 let mut title = "CREATE TABLE".to_string();
242 if v.if_not_exists {
243 title.push_str(" IF NOT EXISTS");
244 }
245
246 let mut table_def = self.doc_display_pass(&v.name);
247
248 let has_columns_or_constraints = match &v.columns {
249 TableFromSourceColumns::NotSpecified => false,
250 _ => true,
251 } || !v.constraints.is_empty();
252
253 if has_columns_or_constraints {
254 let mut items = Vec::new();
255
256 match &v.columns {
257 TableFromSourceColumns::NotSpecified => {}
258 TableFromSourceColumns::Named(cols) => {
259 items.extend(cols.iter().map(|c| self.doc_display_pass(c)));
260 }
261 TableFromSourceColumns::Defined(cols) => {
262 items.extend(cols.iter().map(|c| self.doc_display_pass(c)));
263 }
264 }
265
266 items.extend(v.constraints.iter().map(|c| self.doc_display_pass(c)));
267
268 if !items.is_empty() {
269 table_def = nest(table_def, bracket("(", comma_separated(items), ")"));
270 }
271 }
272
273 docs.push(nest_title(title, table_def));
274
275 // FROM SOURCE
276 let mut from_source = nest_title("FROM SOURCE", self.doc_display_pass(&v.source));
277 if let Some(reference) = &v.external_reference {
278 from_source = nest(
279 from_source,
280 bracket("(REFERENCE = ", self.doc_display_pass(reference), ")"),
281 );
282 }
283 docs.push(from_source);
284
285 if let Some(format) = &v.format {
286 docs.push(self.doc_format_specifier(format));
287 }
288
289 if !v.include_metadata.is_empty() {
290 docs.push(nest_title(
291 "INCLUDE",

Callers 1

to_docMethod · 0.80

Calls 14

nestFunction · 0.85
bracketFunction · 0.85
nest_titleFunction · 0.85
comma_separateFunction · 0.85
doc_display_passMethod · 0.80
doc_format_specifierMethod · 0.80
groupMethod · 0.80
comma_separatedFunction · 0.70
to_stringMethod · 0.45
is_emptyMethod · 0.45
extendMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected