Skip to main content

uqa_sql/binding/
cte_controls.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Static row types and validation for recursive CTE control columns.
8
9use super::{BindingContext, QueryPlan, RowSchema, SQLError, SQLParam, SchemaScope};
10use crate::routines::RoutineResolution;
11use uqa_core::memory::ProductionControl;
12mod production;
13pub use production::{
14    extend_cte_generated_schema_with_control, extend_recursive_cte_binding_schema_with_control,
15};
16
17pub fn hide_recursive_generated_schema(schema: &RowSchema, visible: usize) -> RowSchema {
18    RowSchema::with_recursive_input_with_control(
19        schema,
20        visible,
21        &ProductionControl::uncontrolled(),
22    )
23    .expect("ordinary recursive input schema")
24}
25
26pub fn extend_cte_generated_schema(
27    routines: &dyn RoutineResolution,
28    cte: &crate::plan::CtePlan,
29    schema: RowSchema,
30    params: &[SQLParam],
31) -> Result<RowSchema, SQLError> {
32    extend_cte_generated_schema_with_control(
33        routines,
34        cte,
35        schema,
36        params,
37        &ProductionControl::uncontrolled(),
38    )
39}
40
41pub fn extend_recursive_cte_binding_schema(
42    routines: &dyn RoutineResolution,
43    cte: &crate::plan::CtePlan,
44    schema: RowSchema,
45    params: &[SQLParam],
46) -> Result<RowSchema, SQLError> {
47    extend_recursive_cte_binding_schema_with_control(
48        routines,
49        cte,
50        schema,
51        params,
52        &ProductionControl::uncontrolled(),
53    )
54}
55
56pub fn analyze_recursive_control_step(
57    routines: &dyn RoutineResolution,
58    cte: &crate::plan::CtePlan,
59    step: &QueryPlan,
60    base_schema: RowSchema,
61    params: &[SQLParam],
62    ctes: &BindingContext,
63) -> Result<(), SQLError> {
64    let provisional = extend_recursive_cte_binding_schema(routines, cte, base_schema, params)?;
65    let mut scope = SchemaScope::for_analysis(ctes)?;
66    scope.ctes.insert(cte.name.clone(), provisional);
67    scope.bind_query(routines, step, params, None).map(|_| ())
68}