Skip to main content

reifydb_engine/expression/
eval.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_core::value::column::Column;
5use reifydb_function::registry::Functions;
6use reifydb_rql::expression::Expression;
7use reifydb_runtime::clock::Clock;
8
9use crate::expression::context::EvalContext;
10
11pub fn evaluate(ctx: &EvalContext, expr: &Expression, _functions: &Functions, _clock: &Clock) -> crate::Result<Column> {
12	use crate::expression::{compile::compile_expression, context::CompileContext};
13
14	let compile_ctx = CompileContext {
15		functions: ctx.functions,
16		symbol_table: ctx.symbol_table,
17	};
18	let compiled = compile_expression(&compile_ctx, expr)?;
19	let column = compiled.execute(ctx)?;
20
21	// Ensures that result column data type matches the expected target column type
22	if let Some(ty) = ctx.target.as_ref().map(|c| c.column_type()) {
23		let data = crate::expression::cast::cast_column_data(ctx, &column.data(), ty, &expr.lazy_fragment())?;
24		Ok(Column {
25			name: column.name,
26			data,
27		})
28	} else {
29		Ok(column)
30	}
31}