reifydb_engine/expression/
access.rs1use std::sync::Arc;
5
6use reifydb_core::{
7 error::diagnostic::query::column_not_found, interface::identifier::ColumnPrimitive, value::column::Column,
8};
9use reifydb_rql::expression::AccessPrimitiveExpression;
10use reifydb_type::{error, fragment::Fragment};
11
12use crate::{Result, expression::context::EvalContext};
13
14pub(crate) fn access_lookup(ctx: &EvalContext, expr: &AccessPrimitiveExpression) -> Result<Column> {
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}