Skip to main content

uqa_sql/semantics/rules/
binding.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Unevaluated OLD/NEW query inputs for stored rewrite rules.
8
9mod actions;
10pub use actions::{
11    MutationRuleInput, OwnedInsertRuleQueries, OwnedMutationRuleInput, OwnedRuleQueryInput,
12    OwnedRuleQueryResolver, RuleAction, RuleInputColumns, RuleMutation, RuleQueryInput,
13    RuleQueryResolver,
14};
15
16pub struct RuleColumnMetadata {
17    pub ty: crate::ast::ColumnType,
18    pub collation_oid: Option<u32>,
19}
20
21impl RuleColumnMetadata {
22    /// A projected OLD/NEW field is still a column of the event relation. Its source expression cannot export explicit collation strength across that boundary.
23    pub fn bind_input(&self, expression: crate::ScalarExpr) -> crate::ScalarExpr {
24        if !crate::schema::composites::type_is_collatable(&self.ty) {
25            return expression;
26        }
27        let oid = self.collation_oid.unwrap_or_else(|| {
28            u32::try_from(crate::catalog::type_metadata::pg_type_collation_oid(
29                &self.ty,
30            ))
31            .expect("type collation identity")
32        });
33        crate::ScalarExpr::Collated {
34            expr: Box::new(expression),
35            ty: self.ty.clone(),
36            collation: crate::ir::ResultCollation::new(
37                crate::catalog::collations::derivation::Derivation::implicit(i64::from(oid)),
38                oid,
39            ),
40        }
41    }
42}