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

Function show_subsources

src/sql/src/plan/statement/show.rs:507–552  ·  view source on GitHub ↗
(
    scx: &'a StatementContext<'a>,
    from_schema: Option<ResolvedSchemaName>,
    on_source: Option<ResolvedItemName>,
    filter: Option<ShowStatementFilter<Aug>>,
)

Source from the content-addressed store, hash-verified

505}
506
507fn show_subsources<'a>(
508 scx: &'a StatementContext<'a>,
509 from_schema: Option<ResolvedSchemaName>,
510 on_source: Option<ResolvedItemName>,
511 filter: Option<ShowStatementFilter<Aug>>,
512) -> Result<ShowSelect<'a>, PlanError> {
513 let mut query_filter = Vec::new();
514
515 if on_source.is_none() && from_schema.is_none() {
516 query_filter.push("subsources.id NOT LIKE 's%'".into());
517 let schema_spec = scx.resolve_active_schema().map(|spec| spec.clone())?;
518 query_filter.push(format!("subsources.schema_id = '{schema_spec}'"));
519 }
520
521 if let Some(on_source) = &on_source {
522 let on_item = scx.get_item_by_resolved_name(on_source)?;
523 if on_item.item_type() != CatalogItemType::Source {
524 sql_bail!(
525 "cannot show subsources on {} because it is a {}",
526 on_source.full_name_str(),
527 on_item.item_type(),
528 );
529 }
530 query_filter.push(format!("sources.id = '{}'", on_item.id()));
531 }
532
533 if let Some(schema) = from_schema {
534 let schema_spec = schema.schema_spec();
535 query_filter.push(format!("subsources.schema_id = '{schema_spec}'"));
536 }
537
538 // TODO(database-issues#8322): this looks in both directions for subsources as long as
539 // progress collections still exist
540 let query = format!(
541 "SELECT DISTINCT
542 subsources.name AS name,
543 subsources.type AS type
544 FROM
545 mz_sources AS subsources
546 JOIN mz_internal.mz_object_dependencies deps ON (subsources.id = deps.object_id OR subsources.id = deps.referenced_object_id)
547 JOIN mz_sources AS sources ON (sources.id = deps.object_id OR sources.id = deps.referenced_object_id)
548 WHERE (subsources.type = 'subsource' OR subsources.type = 'progress') AND {}",
549 itertools::join(query_filter, " AND "),
550 );
551 ShowSelect::new(scx, query, filter, None, None)
552}
553
554fn show_views<'a>(
555 scx: &'a StatementContext<'a>,

Callers 1

show_objectsFunction · 0.85

Calls 8

is_noneMethod · 0.80
resolve_active_schemaMethod · 0.80
schema_specMethod · 0.80
pushMethod · 0.45
mapMethod · 0.45
cloneMethod · 0.45
item_typeMethod · 0.45

Tested by

no test coverage detected