reifydb_engine/expression/
access.rs1use std::sync::Arc;
5
6use reifydb_core::{error::diagnostic::query::column_not_found, value::column::Column};
7use reifydb_rql::expression::AccessPrimitiveExpression;
8use reifydb_type::{error, fragment::Fragment};
9
10use crate::expression::context::EvalContext;
11
12pub(crate) fn access_lookup(ctx: &EvalContext, expr: &AccessPrimitiveExpression) -> crate::Result<Column> {
13 use reifydb_core::interface::identifier::ColumnPrimitive;
14
15 let source = match &expr.column.primitive {
17 ColumnPrimitive::Primitive {
18 primitive,
19 ..
20 } => primitive,
21 ColumnPrimitive::Alias(alias) => alias,
22 };
23 let column = expr.column.name.text().to_string();
24
25 let qualified_name = format!("{}.{}", source.text(), &column);
27
28 let matching_col = ctx.columns.iter().find(|col| {
30 if col.name().text() == qualified_name {
32 return true;
33 }
34
35 if matches!(&expr.column.primitive, ColumnPrimitive::Primitive { .. }) {
38 if col.name().text() == column {
39 return !col.name().text().contains('.');
42 }
43 }
44
45 false
46 });
47
48 if let Some(col) = matching_col {
49 Ok(col.with_new_data(col.data().clone()))
51 } else {
52 Err(error!(column_not_found(Fragment::Statement {
54 column: expr.column.name.column(),
55 line: expr.column.name.line(),
56 text: Arc::from(format!("{}.{}", source.text(), &column)),
57 })))
58 }
59}