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;
10
11impl RowSchema {
12    /// 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.
13    pub fn for_result_columns(&self, columns: &[String]) -> Self {
14        let positions = columns
15            .iter()
16            .enumerate()
17            .map(|(position, column)| {
18                if self.columns().get(position) == Some(column) {
19                    Some(position)
20                } else {
21                    self.position(column)
22                }
23            })
24            .collect::<Vec<_>>();
25        Self::with_column_metadata(
26            None,
27            columns.iter().zip(&positions).map(|(column, position)| {
28                (
29                    column.clone(),
30                    position
31                        .and_then(|position| self.column_type(position))
32                        .cloned(),
33                    position.and_then(|position| self.column_collation(position)),
34                )
35            }),
36        )
37        .with_record_metadata(positions.into_iter().enumerate().filter_map(
38            |(output, input)| {
39                self.record_metadata(input?)
40                    .cloned()
41                    .map(|metadata| (output, metadata))
42            },
43        ))
44    }
45}