(&self, context: &FunctionContext)
| 58 | } |
| 59 | |
| 60 | fn execute(&self, context: &FunctionContext) -> FunctionResult<Value> { |
| 61 | if context.arguments.len() != 1 { |
| 62 | return Err(FunctionError::InvalidArgumentCount { |
| 63 | expected: 1, |
| 64 | actual: context.arguments.len(), |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | let node_ref = &context.arguments[0]; |
| 69 | |
| 70 | // Handle direct Node values (from query execution) |
| 71 | match node_ref { |
| 72 | Value::Node(node) => { |
| 73 | let labels: Vec<Value> = node |
| 74 | .labels |
| 75 | .iter() |
| 76 | .map(|label| Value::String(label.clone())) |
| 77 | .collect(); |
| 78 | return Ok(Value::List(labels)); |
| 79 | } |
| 80 | Value::String(variable_name) => { |
| 81 | // First, check if this is a variable name in the aggregation context |
| 82 | // Look through the rows to find the actual node data |
| 83 | if !context.rows.is_empty() { |
| 84 | // Try to find the variable in the first row to get a sample value |
| 85 | for row in &context.rows { |
| 86 | if let Some(Value::Node(node)) = row.get_value(variable_name) { |
| 87 | let labels: Vec<Value> = node |
| 88 | .labels |
| 89 | .iter() |
| 90 | .map(|label| Value::String(label.clone())) |
| 91 | .collect(); |
| 92 | return Ok(Value::List(labels)); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // If not found in rows, continue with node ID lookup for string references |
| 98 | let node_id = variable_name.clone(); |
| 99 | |
| 100 | // Method 1: Try current_graph first (fastest) |
| 101 | if let Some(ref current_graph) = context.current_graph { |
| 102 | if let Some(node) = current_graph.get_node(&node_id) { |
| 103 | let labels: Vec<Value> = node |
| 104 | .labels |
| 105 | .iter() |
| 106 | .map(|label| Value::String(label.clone())) |
| 107 | .collect(); |
| 108 | return Ok(Value::List(labels)); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Method 2: Try storage_manager with graph_name |
| 113 | if let (Some(ref storage_manager), Some(ref graph_name)) = |
| 114 | (&context.storage_manager, &context.graph_name) |
| 115 | { |
| 116 | if let Ok(Some(graph)) = storage_manager.get_graph(graph_name) { |
| 117 | if let Some(node) = graph.get_node(&node_id) { |
nothing calls this directly
no test coverage detected