reifydb-core 0.9.1

Core database interfaces and data structures for ReifyDB
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 ReifyDB

use reifydb_value::{error::NumberOutOfRangeDescriptor, value::value_type::ValueType};

use crate::interface::{
	catalog::property::ColumnPropertyKind,
	resolved::{ResolvedColumn, resolved_column_to_number_descriptor},
};

#[derive(Debug, Clone)]
pub enum TargetColumn {
	Resolved(ResolvedColumn),

	Partial {
		source_name: Option<String>,
		column_name: Option<String>,
		column_type: ValueType,
		properties: Vec<ColumnPropertyKind>,
	},
}

impl TargetColumn {
	pub fn column_type(&self) -> ValueType {
		match self {
			Self::Resolved(col) => col.column_type(),
			Self::Partial {
				column_type,
				..
			} => column_type.clone(),
		}
	}

	pub fn properties(&self) -> Vec<ColumnPropertyKind> {
		match self {
			Self::Resolved(col) => col.properties(),
			Self::Partial {
				properties,
				..
			} => properties.clone(),
		}
	}

	pub fn to_number_descriptor(&self) -> Option<NumberOutOfRangeDescriptor> {
		match self {
			Self::Resolved(col) => Some(resolved_column_to_number_descriptor(col)),
			Self::Partial {
				column_type,
				source_name,
				column_name,
				..
			} => {
				if source_name.is_some() || column_name.is_some() {
					Some(NumberOutOfRangeDescriptor {
						namespace: None,
						table: source_name.clone(),
						column: column_name.clone(),
						column_type: Some(column_type.clone()),
					})
				} else {
					None
				}
			}
		}
	}
}