Skip to main content

reifydb_core/interface/evaluate/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Expression-evaluation contract types shared between the engine, the planner, and the catalog.
5//!
6//! `TargetColumn` is the central value: a column-targeting expression (insert, update, default-value resolution) either
7//! knows the fully-resolved column it is writing to (`TargetColumn::Resolved`) or describes the partial information
8//! available before resolution (`TargetColumn::Partial`). Number-out-of-range descriptor construction lives here too so
9//! range-violation diagnostics are assembled identically by every evaluator.
10
11use reifydb_type::{error::NumberOutOfRangeDescriptor, value::r#type::Type};
12
13use crate::interface::{
14	catalog::property::ColumnPropertyKind,
15	resolved::{ResolvedColumn, resolved_column_to_number_descriptor},
16};
17
18#[derive(Debug, Clone)]
19pub enum TargetColumn {
20	Resolved(ResolvedColumn),
21
22	Partial {
23		source_name: Option<String>,
24		column_name: Option<String>,
25		column_type: Type,
26		properties: Vec<ColumnPropertyKind>,
27	},
28}
29
30impl TargetColumn {
31	pub fn column_type(&self) -> Type {
32		match self {
33			Self::Resolved(col) => col.column_type(),
34			Self::Partial {
35				column_type,
36				..
37			} => column_type.clone(),
38		}
39	}
40
41	pub fn properties(&self) -> Vec<ColumnPropertyKind> {
42		match self {
43			Self::Resolved(col) => col.properties(),
44			Self::Partial {
45				properties,
46				..
47			} => properties.clone(),
48		}
49	}
50
51	pub fn to_number_descriptor(&self) -> Option<NumberOutOfRangeDescriptor> {
52		match self {
53			Self::Resolved(col) => Some(resolved_column_to_number_descriptor(col)),
54			Self::Partial {
55				column_type,
56				source_name,
57				column_name,
58				..
59			} => {
60				if source_name.is_some() || column_name.is_some() {
61					Some(NumberOutOfRangeDescriptor {
62						namespace: None,
63						table: source_name.clone(),
64						column: column_name.clone(),
65						column_type: Some(column_type.clone()),
66					})
67				} else {
68					None
69				}
70			}
71		}
72	}
73}