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

Function generate_subsource_statements

src/sql/src/pure.rs:2354–2445  ·  view source on GitHub ↗
(
    scx: &StatementContext,
    source_name: ResolvedItemName,
    subsources: BTreeMap<UnresolvedItemName, PurifiedSourceExport>,
)

Source from the content-addressed store, hash-verified

2352}
2353
2354pub fn generate_subsource_statements(
2355 scx: &StatementContext,
2356 source_name: ResolvedItemName,
2357 subsources: BTreeMap<UnresolvedItemName, PurifiedSourceExport>,
2358) -> Result<Vec<CreateSubsourceStatement<Aug>>, PlanError> {
2359 // get the first subsource to determine the connection type
2360 if subsources.is_empty() {
2361 return Ok(vec![]);
2362 }
2363 let (_, purified_export) = subsources
2364 .iter()
2365 .next()
2366 .ok_or_else(|| internal_err!("expected at least one subsource"))?;
2367
2368 let statements = match &purified_export.details {
2369 PurifiedExportDetails::Postgres { .. } => {
2370 crate::pure::postgres::generate_create_subsource_statements(
2371 scx,
2372 source_name,
2373 subsources,
2374 )?
2375 }
2376 PurifiedExportDetails::MySql { .. } => {
2377 crate::pure::mysql::generate_create_subsource_statements(scx, source_name, subsources)?
2378 }
2379 PurifiedExportDetails::SqlServer { .. } => {
2380 crate::pure::sql_server::generate_create_subsource_statements(
2381 scx,
2382 source_name,
2383 subsources,
2384 )?
2385 }
2386 PurifiedExportDetails::LoadGenerator { .. } => {
2387 let mut subsource_stmts = Vec::with_capacity(subsources.len());
2388 for (subsource_name, purified_export) in subsources {
2389 let (desc, output) = match purified_export.details {
2390 PurifiedExportDetails::LoadGenerator { table, output } => (table, output),
2391 _ => {
2392 bail_internal!("purified export details must be load generator")
2393 }
2394 };
2395 let desc = desc.ok_or_else(|| {
2396 internal_err!(
2397 "subsources cannot be generated for single-output load generators"
2398 )
2399 })?;
2400
2401 let (columns, table_constraints) = scx.relation_desc_into_table_defs(&desc)?;
2402 let details = SourceExportStatementDetails::LoadGenerator { output };
2403 // Create the subsource statement
2404 let subsource = CreateSubsourceStatement {
2405 name: subsource_name,
2406 columns,
2407 of_source: Some(source_name.clone()),
2408 // unlike sources that come from an external upstream, we
2409 // have more leniency to introduce different constraints
2410 // every time the load generator is run; i.e. we are not as
2411 // worried about introducing junk data.

Calls 8

is_emptyMethod · 0.45
nextMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected