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

Method execute_project_node

graphlite/src/exec/executor.rs:9110–9159  ·  view source on GitHub ↗

Execute a projection node without graph context (scalar-only)

(
        &self,
        node: &PhysicalNode,
        context: &mut ExecutionContext,
        _graph: Option<&Arc<GraphCache>>,
    )

Source from the content-addressed store, hash-verified

9108
9109 /// Execute a projection node without graph context (scalar-only)
9110 fn execute_project_node(
9111 &self,
9112 node: &PhysicalNode,
9113 context: &mut ExecutionContext,
9114 _graph: Option<&Arc<GraphCache>>,
9115 ) -> Result<Vec<Row>, ExecutionError> {
9116 match node {
9117 PhysicalNode::Project {
9118 expressions, input, ..
9119 } => {
9120 // First execute the input
9121 let input_rows = if let Some(graph) = _graph {
9122 self.execute_node_with_graph(input, context, graph)?
9123 } else {
9124 // For standalone projections (like RETURN literals), we might not have meaningful input
9125 // In that case, try to execute without graph, and if it fails, assume it's a standalone projection
9126 match self.execute_node_without_graph(input, context) {
9127 Ok(rows) => rows,
9128 Err(_) => {
9129 // If input execution fails, assume this is a standalone projection
9130 // Create a single empty row as input for the projection
9131 vec![Row::from_values(std::collections::HashMap::new())]
9132 }
9133 }
9134 };
9135
9136 // Apply projections to each row
9137 let mut result_rows = Vec::new();
9138 for _row in input_rows {
9139 let mut projected_values = std::collections::HashMap::new();
9140
9141 for proj in expressions {
9142 let value = self.evaluate_expression(&proj.expression, context)?;
9143 let alias = proj
9144 .alias
9145 .clone()
9146 .unwrap_or_else(|| format!("col_{}", projected_values.len()));
9147 projected_values.insert(alias, value);
9148 }
9149
9150 result_rows.push(Row::from_values(projected_values));
9151 }
9152
9153 Ok(result_rows)
9154 }
9155 _ => Err(ExecutionError::RuntimeError(
9156 "Expected Project node".to_string(),
9157 )),
9158 }
9159 }
9160
9161 /// Validate graph expression via catalog
9162 fn validate_graph_expression_via_catalog(&self, graph_expression: &GraphExpression) -> bool {

Callers 1

Calls 5

cloneMethod · 0.80
evaluate_expressionMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected