Apply a property assignment to entities in a row using proper storage mutation flow
(
&self,
property: &crate::ast::PropertyAccess,
new_value: crate::storage::Value,
row: &Row,
context: &ExecutionContext,
)
| 7377 | |
| 7378 | /// Apply a property assignment to entities in a row using proper storage mutation flow |
| 7379 | fn apply_property_assignment( |
| 7380 | &self, |
| 7381 | property: &crate::ast::PropertyAccess, |
| 7382 | new_value: crate::storage::Value, |
| 7383 | row: &Row, |
| 7384 | context: &ExecutionContext, |
| 7385 | ) -> Result<(), ExecutionError> { |
| 7386 | use crate::storage::Value; |
| 7387 | |
| 7388 | // PropertyAccess has structure: {object: String, property: String} |
| 7389 | // The object field contains the variable name |
| 7390 | let entity_value = row.values.get(&property.object).ok_or_else(|| { |
| 7391 | ExecutionError::RuntimeError(format!("Variable '{}' not found in row", property.object)) |
| 7392 | })?; |
| 7393 | |
| 7394 | // Extract node ID from the entity value |
| 7395 | let node_id = match entity_value { |
| 7396 | Value::Node(node_ref) => &node_ref.id, |
| 7397 | _ => { |
| 7398 | return Err(ExecutionError::RuntimeError( |
| 7399 | "Property assignment only supported on nodes".to_string(), |
| 7400 | )); |
| 7401 | } |
| 7402 | }; |
| 7403 | |
| 7404 | // Get mutable access to the graph through the storage manager |
| 7405 | // This follows the same pattern as DataStatementExecutors |
| 7406 | let graph_name = context.get_current_graph_name().ok_or_else(|| { |
| 7407 | ExecutionError::RuntimeError( |
| 7408 | "No graph context available for property assignment".to_string(), |
| 7409 | ) |
| 7410 | })?; |
| 7411 | |
| 7412 | // Use the storage manager to update the node property following DataStatement pattern |
| 7413 | if let Some(ref storage_manager) = context.storage_manager { |
| 7414 | // Get the graph from storage (this returns an owned GraphCache) |
| 7415 | let mut graph = storage_manager |
| 7416 | .get_graph(&graph_name) |
| 7417 | .map_err(|e| ExecutionError::RuntimeError(format!("Failed to get graph: {}", e)))? |
| 7418 | .ok_or_else(|| ExecutionError::RuntimeError("Graph not found".to_string()))?; |
| 7419 | |
| 7420 | // Modify the graph |
| 7421 | if let Some(node) = graph.get_node_mut(node_id) { |
| 7422 | node.set_property(property.property.clone(), new_value.clone()); |
| 7423 | log::debug!( |
| 7424 | "SET {}.{} = {:?} (node_id: {})", |
| 7425 | property.object, |
| 7426 | property.property, |
| 7427 | new_value, |
| 7428 | node_id |
| 7429 | ); |
| 7430 | |
| 7431 | // Save the modified graph back to storage |
| 7432 | // TODO: This should go through the unified storage flow for proper transaction support |
| 7433 | // For now, we need to figure out how to save the graph back |
| 7434 | log::debug!( |
| 7435 | "Graph modification completed - needs proper persistence implementation" |
| 7436 | ); |
no test coverage detected