Resolve the node adjacent to an edge pattern
(
&self,
all_elements: &[PatternElement],
edge_idx: usize,
direction: i32, // -1 for source, +1 for target
)
| 210 | |
| 211 | /// Resolve the node adjacent to an edge pattern |
| 212 | fn resolve_adjacent_node( |
| 213 | &self, |
| 214 | all_elements: &[PatternElement], |
| 215 | edge_idx: usize, |
| 216 | direction: i32, // -1 for source, +1 for target |
| 217 | ) -> Result<String, PlanningError> { |
| 218 | let node_idx = if direction < 0 { |
| 219 | if edge_idx == 0 { |
| 220 | return Err(PlanningError::InvalidPattern( |
| 221 | "Edge pattern must be preceded by a source node".to_string(), |
| 222 | )); |
| 223 | } |
| 224 | edge_idx - 1 |
| 225 | } else { |
| 226 | if edge_idx >= all_elements.len() - 1 { |
| 227 | return Err(PlanningError::InvalidPattern( |
| 228 | "Edge pattern must be followed by a target node".to_string(), |
| 229 | )); |
| 230 | } |
| 231 | edge_idx + 1 |
| 232 | }; |
| 233 | |
| 234 | match &all_elements[node_idx] { |
| 235 | PatternElement::Node(node_pattern) => { |
| 236 | if let Some(ref identifier) = node_pattern.identifier { |
| 237 | // Look up the storage ID from our mappings |
| 238 | if let Some(node_info) = self.identifier_mappings.get(identifier) { |
| 239 | Ok(node_info.storage_id.clone()) |
| 240 | } else { |
| 241 | Err(PlanningError::IdentifierNotFound(identifier.clone())) |
| 242 | } |
| 243 | } else { |
| 244 | // Anonymous node - generate ID from content |
| 245 | let properties = if let Some(ref prop_map) = node_pattern.properties { |
| 246 | self.extract_properties(prop_map)? |
| 247 | } else { |
| 248 | HashMap::new() |
| 249 | }; |
| 250 | |
| 251 | if node_pattern.labels.is_empty() && properties.is_empty() { |
| 252 | return Err(PlanningError::InvalidPattern( |
| 253 | "Cannot use empty anonymous node in edge pattern".to_string(), |
| 254 | )); |
| 255 | } |
| 256 | |
| 257 | Ok(Self::generate_node_content_id( |
| 258 | &node_pattern.labels, |
| 259 | &properties, |
| 260 | )) |
| 261 | } |
| 262 | } |
| 263 | _ => Err(PlanningError::InvalidPattern( |
| 264 | "Expected node pattern adjacent to edge".to_string(), |
| 265 | )), |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | /// Extract properties from a property map |
no test coverage detected