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

Method doc_create_index

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

Source from the content-addressed store, hash-verified

505 }
506
507 pub(crate) fn doc_create_index<'a, T: AstInfo>(
508 &'a self,
509 v: &'a CreateIndexStatement<T>,
510 ) -> RcDoc<'a> {
511 let mut docs = Vec::new();
512
513 // CREATE [DEFAULT] INDEX [IF NOT EXISTS] [name]
514 let mut title = "CREATE".to_string();
515 if v.key_parts.is_none() {
516 title.push_str(" DEFAULT");
517 }
518 title.push_str(" INDEX");
519 if v.if_not_exists {
520 title.push_str(" IF NOT EXISTS");
521 }
522
523 if let Some(name) = &v.name {
524 // A bare `in` index name re-lexes as the start of the optional
525 // `IN CLUSTER` clause, so force it quoted (matching the
526 // `CreateIndexStatement` AstDisplay impl). `in` is fine bare in a
527 // required-name position, so this isn't a `can_be_printed_bare` case.
528 let name_doc = if name.as_str().eq_ignore_ascii_case("in") {
529 RcDoc::text(format!("\"{}\"", name.as_str()))
530 } else {
531 self.doc_display_pass(name)
532 };
533 docs.push(nest_title(title, name_doc));
534 } else {
535 docs.push(RcDoc::text(title));
536 }
537
538 // IN CLUSTER
539 if let Some(cluster) = &v.in_cluster {
540 docs.push(nest_title("IN CLUSTER", self.doc_display_pass(cluster)));
541 }
542
543 // ON table_name [(key_parts)]
544 let on_clause = if let Some(key_parts) = &v.key_parts {
545 nest(
546 self.doc_display_pass(&v.on_name),
547 bracket(
548 "(",
549 comma_separate(|k| self.doc_display_pass(k), key_parts),
550 ")",
551 ),
552 )
553 } else {
554 self.doc_display_pass(&v.on_name)
555 };
556 docs.push(nest_title("ON", on_clause));
557
558 // WITH options
559 if !v.with_options.is_empty() {
560 docs.push(bracket(
561 "WITH (",
562 comma_separate(|wo| self.doc_display_pass(wo), &v.with_options),
563 ")",
564 ));

Callers 1

to_docMethod · 0.80

Calls 11

nest_titleFunction · 0.85
nestFunction · 0.85
bracketFunction · 0.85
comma_separateFunction · 0.85
is_noneMethod · 0.80
doc_display_passMethod · 0.80
groupMethod · 0.80
to_stringMethod · 0.45
as_strMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected