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

Function purify_alter_source

src/sql/src/pure.rs:1365–1452  ·  view source on GitHub ↗

On success, returns the details on new subsources and updated 'options' that sequencing expects for handling `ALTER SOURCE` statements.

(
    catalog: impl SessionCatalog,
    stmt: AlterSourceStatement<Aug>,
    storage_configuration: &StorageConfiguration,
)

Source from the content-addressed store, hash-verified

1363/// On success, returns the details on new subsources and updated
1364/// 'options' that sequencing expects for handling `ALTER SOURCE` statements.
1365async fn purify_alter_source(
1366 catalog: impl SessionCatalog,
1367 stmt: AlterSourceStatement<Aug>,
1368 storage_configuration: &StorageConfiguration,
1369) -> Result<PurifiedStatement, PlanError> {
1370 let scx = StatementContext::new(None, &catalog);
1371 let AlterSourceStatement {
1372 source_name: unresolved_source_name,
1373 action,
1374 if_exists,
1375 } = stmt;
1376
1377 // Get name.
1378 let item = match scx.resolve_item(RawItemName::Name(unresolved_source_name.clone())) {
1379 Ok(item) => item,
1380 Err(_) if if_exists => {
1381 return Ok(PurifiedStatement::PurifiedAlterSource {
1382 alter_source_stmt: AlterSourceStatement {
1383 source_name: unresolved_source_name,
1384 action,
1385 if_exists,
1386 },
1387 });
1388 }
1389 Err(e) => return Err(e),
1390 };
1391
1392 // Ensure it's an ingestion-based and alterable source.
1393 let desc = match item.source_desc()? {
1394 Some(desc) => desc.clone().into_inline_connection(scx.catalog),
1395 None => {
1396 sql_bail!("cannot ALTER this type of source")
1397 }
1398 };
1399
1400 let source_name = item.name();
1401
1402 let resolved_source_name = ResolvedItemName::Item {
1403 id: item.id(),
1404 qualifiers: item.name().qualifiers.clone(),
1405 full_name: scx.catalog.resolve_full_name(source_name),
1406 print_id: true,
1407 version: RelationVersionSelector::Latest,
1408 };
1409
1410 let partial_name = scx.catalog.minimal_qualification(source_name);
1411
1412 match action {
1413 AlterSourceAction::AddSubsources {
1414 external_references,
1415 options,
1416 } => {
1417 if scx.catalog.system_vars().enable_create_table_from_source()
1418 && scx.catalog.system_vars().force_source_table_syntax()
1419 {
1420 Err(PlanError::UseTablesForSources(
1421 "ALTER SOURCE .. ADD SUBSOURCES ..".to_string(),
1422 ))?;

Callers 1

purify_statementFunction · 0.85

Calls 14

NameClass · 0.50
resolve_itemMethod · 0.45
cloneMethod · 0.45
source_descMethod · 0.45
nameMethod · 0.45
idMethod · 0.45
resolve_full_nameMethod · 0.45
minimal_qualificationMethod · 0.45

Tested by

no test coverage detected