(
scx: &'a StatementContext<'a>,
from_schema: Option<ResolvedSchemaName>,
on_source: Option<ResolvedItemName>,
filter: Option<ShowStatementFilter<Aug>>,
)
| 505 | } |
| 506 | |
| 507 | fn 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 | |
| 554 | fn show_views<'a>( |
| 555 | scx: &'a StatementContext<'a>, |
no test coverage detected