Skip to main content

uqa_sql/schema/
result_columns.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Dense output descriptors without retained executor slots or source namespaces.
8
9use super::RowSchema;
10use crate::SQLError;
11use uqa_core::memory::ProductionControl;
12
13impl RowSchema {
14    /// Select public output metadata in result order. Repeated labels retain their positional identities; a source with a different layout resolves a label through its existing schema index.
15    pub fn for_result_columns(&self, columns: &[String]) -> Self {
16        self.for_result_columns_with_control(columns, &ProductionControl::uncontrolled())
17            .expect("ordinary result descriptor")
18    }
19
20    /// Publish dense public metadata while retaining selected record descriptors and admitting all new column, identity and type storage before construction.
21    pub fn for_result_columns_with_control(
22        &self,
23        columns: &[String],
24        control: &ProductionControl<'_>,
25    ) -> Result<Self, SQLError> {
26        Self::with_output_metadata_with_control(
27            None,
28            columns.iter().enumerate().map(|(position, column)| {
29                let position = if self.columns().get(position) == Some(column) {
30                    Some(position)
31                } else {
32                    self.position(column)
33                };
34                (
35                    column.as_str(),
36                    position.and_then(|position| self.column_type(position)),
37                    position.and_then(|position| self.column_collation(position)),
38                    position
39                        .and_then(|position| self.record_metadata(position))
40                        .cloned(),
41                )
42            }),
43            false,
44            control,
45        )
46    }
47
48    /// Project explicitly selected source positions into a dense public result. This combines logical-position remapping and result publication without constructing temporary source names or hidden namespace indexes.
49    pub fn for_selected_result_columns_with_control<'a>(
50        &self,
51        columns: impl IntoIterator<Item = (&'a str, usize)>,
52        control: &ProductionControl<'_>,
53    ) -> Result<Self, SQLError> {
54        Self::with_output_metadata_with_control(
55            None,
56            columns.into_iter().map(|(name, position)| {
57                (
58                    name,
59                    self.column_type(position),
60                    self.inherited_column_collation(position),
61                    self.record_metadata(position).cloned(),
62                )
63            }),
64            false,
65            control,
66        )
67    }
68}