Skip to main content

reifydb_core/interface/evaluate/
mod.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_type::{error::diagnostic::number::NumberOfRangeColumnDescriptor, value::r#type::Type};
5
6use crate::interface::{
7	catalog::policy::ColumnPolicyKind,
8	resolved::{ResolvedColumn, resolved_column_to_number_descriptor},
9};
10
11/// Represents target column information for evaluation
12#[derive(Debug, Clone)]
13pub enum TargetColumn {
14	/// Fully resolved column with complete source information
15	Resolved(ResolvedColumn),
16	/// Partial column information with type, policies, and optional names for error reporting
17	Partial {
18		source_name: Option<String>,
19		column_name: Option<String>,
20		column_type: Type,
21		policies: Vec<ColumnPolicyKind>,
22	},
23}
24
25impl TargetColumn {
26	/// Get the column type
27	pub fn column_type(&self) -> Type {
28		match self {
29			Self::Resolved(col) => col.column_type(),
30			Self::Partial {
31				column_type,
32				..
33			} => column_type.clone(),
34		}
35	}
36
37	/// Get the column policies
38	pub fn policies(&self) -> Vec<ColumnPolicyKind> {
39		match self {
40			Self::Resolved(col) => col.policies(),
41			Self::Partial {
42				policies,
43				..
44			} => policies.clone(),
45		}
46	}
47
48	/// Convert to NumberOfRangeColumnDescriptor for error reporting
49	pub fn to_number_descriptor(&self) -> Option<NumberOfRangeColumnDescriptor<'_>> {
50		match self {
51			Self::Resolved(col) => Some(resolved_column_to_number_descriptor(col)),
52			Self::Partial {
53				column_type,
54				source_name,
55				column_name,
56				..
57			} => {
58				// Only create descriptor if we have at least some name information
59				if source_name.is_some() || column_name.is_some() {
60					Some(NumberOfRangeColumnDescriptor {
61						namespace: None,
62						table: source_name.as_deref(),
63						column: column_name.as_deref(),
64						column_type: Some(column_type.clone()),
65					})
66				} else {
67					None
68				}
69			}
70		}
71	}
72}