Skip to main content

uqa_sql/binding/routine_parameters/
production.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! A routine namespace shares its immutable admitted names and schema across analysis scopes.
8
9use super::{
10    ColumnType, RoutineParameterData, RoutineParameterScope, RowSchema, SQLError,
11    ROUTINE_PARAMETERS,
12};
13use uqa_core::memory::{ProductionControl, ProductionVec};
14
15#[cfg(test)]
16mod tests;
17
18impl RoutineParameterScope {
19    pub fn new_with_control<'a>(
20        function: &str,
21        columns: impl Iterator<Item = (&'a str, Option<&'a ColumnType>)> + Clone,
22        control: &ProductionControl<'_>,
23    ) -> Result<Self, SQLError> {
24        control.check()?;
25        let schema = RowSchema::with_parameter_metadata_with_control(
26            function,
27            *ROUTINE_PARAMETERS,
28            columns.clone(),
29            control,
30        )?;
31        let function = control.copy_text(function)?;
32        let mut names = ProductionVec::new(*control);
33        names.reserve(columns.clone().count())?;
34        for (name, _) in columns {
35            names.push_produced(control.copy_text(name)?)?;
36        }
37        let (function, function_memory) = function.into_parts();
38        let (names, names_memory) = names.finish()?.into_parts();
39        let data = control
40            .finish(
41                RoutineParameterData {
42                    function,
43                    names,
44                    schema,
45                },
46                control.combine(function_memory, names_memory),
47            )?
48            .into_shared(control)?;
49        Ok(Self { data })
50    }
51}