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

Function purify_source_exports

src/sql/src/pure/postgres.rs:361–551  ·  view source on GitHub ↗

Purify the requested external references, returning a set of purified source exports corresponding to external tables, and and additional fields necessary to generate relevant statements and update statement options

(
    client: &Client,
    retrieved_references: &RetrievedSourceReferences,
    requested_references: &Option<ExternalReferences>,
    mut text_columns: Vec<UnresolvedItemName>,
    mut exclude_colum

Source from the content-addressed store, hash-verified

359// source exports corresponding to external tables, and and additional
360// fields necessary to generate relevant statements and update statement options
361pub(super) async fn purify_source_exports(
362 client: &Client,
363 retrieved_references: &RetrievedSourceReferences,
364 requested_references: &Option<ExternalReferences>,
365 mut text_columns: Vec<UnresolvedItemName>,
366 mut exclude_columns: Vec<UnresolvedItemName>,
367 unresolved_source_name: &UnresolvedItemName,
368 reference_policy: &SourceReferencePolicy,
369) -> Result<PurifiedSourceExports, PlanError> {
370 let requested_exports = match requested_references.as_ref() {
371 Some(requested) if matches!(reference_policy, SourceReferencePolicy::NotAllowed) => {
372 Err(PlanError::UseTablesForSources(requested.to_string()))?
373 }
374 Some(requested) => retrieved_references
375 .requested_source_exports(Some(requested), unresolved_source_name)?,
376 None => {
377 if matches!(reference_policy, SourceReferencePolicy::Required) {
378 Err(PgSourcePurificationError::RequiresExternalReferences)?
379 }
380
381 // If no external reference is specified, it does not make sense to include
382 // text columns.
383 if !text_columns.is_empty() {
384 Err(
385 PgSourcePurificationError::UnnecessaryOptionsWithoutReferences(
386 "TEXT COLUMNS".to_string(),
387 ),
388 )?
389 }
390
391 // If no external reference is specified, it does not make sense to include
392 // exclude columns.
393 if !exclude_columns.is_empty() {
394 Err(
395 PgSourcePurificationError::UnnecessaryOptionsWithoutReferences(
396 "EXCLUDE COLUMNS".to_string(),
397 ),
398 )?
399 }
400
401 return Ok(PurifiedSourceExports {
402 source_exports: BTreeMap::new(),
403 normalized_text_columns: vec![],
404 });
405 }
406 };
407
408 if requested_exports.is_empty() {
409 sql_bail!(
410 "[internal error]: Postgres reference {} did not match any tables",
411 requested_references
412 .as_ref()
413 .unwrap()
414 .to_ast_string_simple()
415 );
416 }
417
418 super::validate_source_export_names(&requested_exports)?;

Callers

nothing calls this directly

Calls 15

expectMethod · 0.80
postgres_descMethod · 0.80
sortMethod · 0.80
all_referencesMethod · 0.80
map_column_refsFunction · 0.70
as_refMethod · 0.45
to_stringMethod · 0.45
is_emptyMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected