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,
)
| 563 | /// Returns an error if any column reference in `cols` is not part of a table in the |
| 564 | /// provided `tables`. |
| 565 | fn 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 | } |
no test coverage detected