MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / evaluate_path_constructor

Method evaluate_path_constructor

graphlite/src/exec/executor.rs:4900–4952  ·  view source on GitHub ↗

Evaluate a PATH constructor: PATH[expr1, expr2, ...]

(
        &self,
        path_constructor: &crate::ast::PathConstructor,
        context: &ExecutionContext,
    )

Source from the content-addressed store, hash-verified

4898
4899 /// Evaluate a PATH constructor: PATH[expr1, expr2, ...]
4900 fn evaluate_path_constructor(
4901 &self,
4902 path_constructor: &crate::ast::PathConstructor,
4903 context: &ExecutionContext,
4904 ) -> Result<Value, ExecutionError> {
4905 use crate::storage::value::{PathElement, PathValue};
4906
4907 // Evaluate each expression in the PATH constructor
4908 let mut path_elements = Vec::new();
4909
4910 for (i, expr) in path_constructor.elements.iter().enumerate() {
4911 let value = self.evaluate_expression(expr, context)?;
4912
4913 // Convert the evaluated value to a path element
4914 match value {
4915 Value::String(node_id) => {
4916 // Even indices are nodes, odd indices are edges
4917 if i % 2 == 0 {
4918 path_elements.push(PathElement {
4919 node_id,
4920 edge_id: None,
4921 });
4922 } else {
4923 // This is an edge, update the previous node element
4924 if let Some(last_element) = path_elements.last_mut() {
4925 last_element.edge_id = Some(node_id);
4926 }
4927 }
4928 }
4929 Value::Number(n) => {
4930 // Convert number to string ID
4931 let id_str = n.to_string();
4932 if i % 2 == 0 {
4933 path_elements.push(PathElement {
4934 node_id: id_str,
4935 edge_id: None,
4936 });
4937 } else if let Some(last_element) = path_elements.last_mut() {
4938 last_element.edge_id = Some(id_str);
4939 }
4940 }
4941 _ => {
4942 return Err(ExecutionError::RuntimeError(format!(
4943 "PATH constructor element must be a string or number, got: {:?}",
4944 value
4945 )));
4946 }
4947 }
4948 }
4949
4950 let path_value = PathValue::from_elements(path_elements);
4951 Ok(Value::Path(path_value))
4952 }
4953
4954 /// Evaluate a CAST expression: CAST(expr AS type-spec)
4955 fn evaluate_cast_expression(

Callers 2

evaluate_expressionMethod · 0.80

Calls 2

iterMethod · 0.45
evaluate_expressionMethod · 0.45

Tested by

no test coverage detected