reifydb_engine/expression/
access.rs1use std::sync::Arc;
5
6use reifydb_core::{
7 error::diagnostic::query::column_not_found, interface::identifier::ColumnShape, value::column::Column,
8};
9use reifydb_rql::expression::AccessShapeExpression;
10use reifydb_type::{error, fragment::Fragment};
11
12use crate::{Result, expression::context::EvalContext};
13
14pub(crate) fn access_lookup(ctx: &EvalContext, expr: &AccessShapeExpression) -> Result<Column> {
15 let source = match &expr.column.shape {
17 ColumnShape::Qualified {
18 name,
19 ..
20 } => name,
21 ColumnShape::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.shape, ColumnShape::Qualified { .. }) && col.name().text() == column {
38 return !col.name().text().contains('.');
41 }
42
43 false
44 });
45
46 if let Some(col) = matching_col {
47 Ok(col.with_new_data(col.data().clone()))
49 } else {
50 Err(error!(column_not_found(Fragment::Statement {
52 column: expr.column.name.column(),
53 line: expr.column.name.line(),
54 text: Arc::from(format!("{}.{}", source.text(), &column)),
55 })))
56 }
57}