Skip to main content

uqa_sql/catalog/
schema_production.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Fixed catalog declarations separate inline metadata from allocation-bearing type construction.
8
9use super::VirtualRelation;
10use crate::{ColumnType, SQLError};
11use uqa_core::memory::{Produced, ProductionControl, ProductionVec};
12
13pub(super) enum CatalogColumnType {
14    Inline(ColumnType),
15    Array(ColumnType),
16    Domain(u32),
17}
18impl CatalogColumnType {
19    fn produce(self, control: &ProductionControl<'_>) -> Result<Produced<ColumnType>, SQLError> {
20        Ok(match self {
21            Self::Inline(ty) => control.finish(ty, control.empty_reservation())?,
22            Self::Array(element) => ColumnType::array_with_control(
23                control.finish(element, control.empty_reservation())?,
24                control,
25            )?,
26            Self::Domain(oid) => super::system_catalog_domain_with_control(oid, control)?
27                .expect("fixed catalog domain"),
28        })
29    }
30}
31impl VirtualRelation {
32    pub fn schema_with_control(
33        self,
34        control: &ProductionControl<'_>,
35    ) -> Result<Produced<Vec<(String, ColumnType)>>, SQLError> {
36        control.check()?;
37        let mut columns = ProductionVec::new(*control);
38        let mut status: Result<(), SQLError> = Ok(());
39        self.visit_columns(&mut |name, ty| {
40            if status.is_ok() {
41                status = (|| {
42                    let (name, name_memory) = control.copy_text(name)?.into_parts();
43                    let (ty, type_memory) = ty.produce(control)?.into_parts();
44                    columns.push_produced(
45                        control.finish((name, ty), control.combine(name_memory, type_memory))?,
46                    )?;
47                    Ok(())
48                })();
49            }
50        });
51        status?;
52        Ok(columns.finish()?)
53    }
54}
55
56#[cfg(test)]
57mod tests;