uqa_sql/semantics/
bound_columns.rs1use crate::{RowSchema, SQLError};
10
11pub fn bound_source_schema(
12 schema: &RowSchema,
13 bound: Option<&[String]>,
14) -> Result<RowSchema, SQLError> {
15 let Some(bound) = bound else {
16 return Ok(schema.clone());
17 };
18 let columns = bound_source_column_names(schema.columns().to_vec(), Some(bound))?;
19 Ok(RowSchema::select(
20 schema,
21 &columns
22 .into_iter()
23 .map(|name| (name.clone(), name))
24 .collect::<Vec<_>>(),
25 ))
26}
27
28pub fn bound_source_column_names(
29 current: Vec<String>,
30 bound: Option<&[String]>,
31) -> Result<Vec<String>, SQLError> {
32 let Some(bound) = bound else {
33 return Ok(current);
34 };
35 for name in bound {
36 if !current.contains(name) {
37 return Err(SQLError::UnknownColumn(name.clone()));
38 }
39 }
40 Ok(bound.to_vec())
41}