Skip to main content

uqa_sql/binding/production/
entries.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Controlled schema entries share the same analysis scope and carry its invoking allowance through every nested bind.
8
9use super::ControlledBindingContext;
10use crate::{
11    plan::{QueryPlan, SourcePlan},
12    routines::RoutineResolution,
13    RowSchema, SQLError, SQLParam,
14};
15use uqa_core::memory::ProductionControl;
16
17pub fn analyze_query_plan_schema_with_control(
18    routines: &dyn RoutineResolution,
19    query: &QueryPlan,
20    params: &[SQLParam],
21    scope: ControlledBindingContext<'_>,
22    outer: Option<&RowSchema>,
23    control: &ProductionControl<'_>,
24) -> Result<RowSchema, SQLError> {
25    super::super::SchemaScope::for_analysis_with_control(scope, control)?
26        .bind_query(routines, query, params, outer)
27}
28
29pub fn bind_query_plan_schema_with_control(
30    routines: &dyn RoutineResolution,
31    query: &QueryPlan,
32    params: &[SQLParam],
33    scope: ControlledBindingContext<'_>,
34    outer: Option<&RowSchema>,
35    control: &ProductionControl<'_>,
36) -> Result<RowSchema, SQLError> {
37    super::super::SchemaScope::from_context_with_control(scope, control)?
38        .bind_query(routines, query, params, outer)
39}
40
41pub fn analyze_source_plan_schema_with_control(
42    routines: &dyn RoutineResolution,
43    source: &SourcePlan,
44    params: &[SQLParam],
45    scope: ControlledBindingContext<'_>,
46    outer: Option<&RowSchema>,
47    control: &ProductionControl<'_>,
48) -> Result<RowSchema, SQLError> {
49    let subqueries = scope.scalar_subqueries;
50    super::super::SchemaScope::for_analysis_with_control(scope, control)?
51        .bind_source(routines, source, subqueries, params, outer)
52}
53
54pub fn analyze_expression_plan_type_with_control(
55    routines: &dyn RoutineResolution,
56    plan: &crate::plan::ExpressionPlan,
57    params: &[SQLParam],
58    scope: ControlledBindingContext<'_>,
59    control: &ProductionControl<'_>,
60) -> Result<Option<uqa_core::memory::Produced<crate::ColumnType>>, SQLError> {
61    let empty = RowSchema::new_with_control(
62        control.finish(Vec::new(), control.empty_reservation())?,
63        control,
64    )?;
65    super::super::SchemaScope::for_analysis_with_control(scope, control)?
66        .bind_expression_type_with_control(routines, &plan.scalar, &empty, &plan.subqueries, params)
67}
68
69/// Bind preceding peers and lexical ancestors with the original schema-analysis mode and allowance.
70pub fn bind_source_plan_schema_in_scope_with_control(
71    routines: &dyn RoutineResolution,
72    source: &SourcePlan,
73    params: &[SQLParam],
74    scope: ControlledBindingContext<'_>,
75    names: crate::binding::SourceScope<'_>,
76    control: &ProductionControl<'_>,
77) -> Result<RowSchema, SQLError> {
78    let subqueries = scope.scalar_subqueries;
79    super::super::SchemaScope::from_context_with_control(scope, control)?
80        .bind_source_in_scope(routines, source, subqueries, params, names)
81}
82
83/// Bind one complete source with the same preceding and outer scope as ordinary native binding.
84pub fn bind_source_plan_schema_with_control(
85    routines: &dyn RoutineResolution,
86    source: &SourcePlan,
87    params: &[SQLParam],
88    scope: ControlledBindingContext<'_>,
89    outer: Option<&RowSchema>,
90    control: &ProductionControl<'_>,
91) -> Result<RowSchema, SQLError> {
92    let subqueries = scope.scalar_subqueries;
93    super::super::SchemaScope::from_context_with_control(scope, control)?
94        .bind_source(routines, source, subqueries, params, outer)
95}