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

Function normalize_column_refs

src/sql/src/pure/sql_server.rs:565–601  ·  view source on GitHub ↗

Normalize the provided `cols` references to a sorted and deduplicated list of [`WithOptionValue`]s. Returns an error if any column reference in `cols` is not part of a table in the provided `tables`.

(
    cols: &[UnresolvedItemName],
    reference_resolver: &SourceReferenceResolver,
    tables: &[RequestedSourceExport<SqlServerTableDesc>],
    option_name: SqlServerConfigOptionName,
)

Source from the content-addressed store, hash-verified

563/// Returns an error if any column reference in `cols` is not part of a table in the
564/// provided `tables`.
565fn normalize_column_refs(
566 cols: &[UnresolvedItemName],
567 reference_resolver: &SourceReferenceResolver,
568 tables: &[RequestedSourceExport<SqlServerTableDesc>],
569 option_name: SqlServerConfigOptionName,
570) -> Result<Vec<WithOptionValue<Aug>>, SqlServerSourcePurificationError> {
571 let (seq, unknown): (Vec<_>, Vec<_>) = cols.into_iter().partition(|name| {
572 let (column_name, qual) = name.0.split_last().expect("non-empty");
573 match reference_resolver.resolve_idx(qual) {
574 // TODO(sql_server3): This needs to also introduce the maximum qualification
575 // on the columns, i.e. ensure they have the schema name.
576 Ok(idx) => tables[idx]
577 .meta
578 .columns
579 .iter()
580 .any(|n| &*n.name == column_name.as_str()),
581 Err(_) => false,
582 }
583 });
584
585 if !unknown.is_empty() {
586 return Err(SqlServerSourcePurificationError::DanglingColumns {
587 option_name: option_name.to_string(),
588 items: unknown.into_iter().cloned().collect(),
589 });
590 }
591
592 let mut seq: Vec<_> = seq
593 .into_iter()
594 .cloned()
595 .map(WithOptionValue::UnresolvedItemName)
596 .collect();
597
598 seq.sort();
599 seq.dedup();
600 Ok(seq)
601}

Callers 1

purify_source_exportsFunction · 0.70

Calls 12

partitionMethod · 0.80
expectMethod · 0.80
resolve_idxMethod · 0.80
anyMethod · 0.80
sortMethod · 0.80
into_iterMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45
to_stringMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected