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

Method execute_match_with_context

graphlite/src/exec/executor.rs:1286–1349  ·  view source on GitHub ↗

Execute a MATCH clause with context support for WITH queries

(
        &self,
        match_clause: &MatchClause,
        context: &ExecutionContext,
    )

Source from the content-addressed store, hash-verified

1284
1285 /// Execute a MATCH clause with context support for WITH queries
1286 fn execute_match_with_context(
1287 &self,
1288 match_clause: &MatchClause,
1289 context: &ExecutionContext,
1290 ) -> Result<Vec<Row>, ExecutionError> {
1291 // Extract all variable names from the MATCH clause patterns
1292 let mut variables = std::collections::HashSet::<String>::new();
1293 for pattern in &match_clause.patterns {
1294 for element in &pattern.elements {
1295 match element {
1296 crate::ast::PatternElement::Node(node) => {
1297 if let Some(ref var) = node.identifier {
1298 variables.insert(var.clone());
1299 }
1300 }
1301 crate::ast::PatternElement::Edge(edge) => {
1302 if let Some(ref var) = edge.identifier {
1303 variables.insert(var.clone());
1304 }
1305 }
1306 }
1307 }
1308 }
1309
1310 // Create RETURN items for all variables found in the MATCH clause
1311 let return_items: Vec<ReturnItem> = variables
1312 .into_iter()
1313 .map(|var| ReturnItem {
1314 expression: Expression::Variable(Variable {
1315 name: var.clone(),
1316 location: Location::default(),
1317 }),
1318 alias: Some(var),
1319 location: Location::default(),
1320 })
1321 .collect();
1322
1323 // If no variables found, return empty result
1324 if return_items.is_empty() {
1325 return Ok(vec![]);
1326 }
1327
1328 // Create a basic query with the MATCH clause and RETURN all variables
1329 let basic_query = BasicQuery {
1330 match_clause: match_clause.clone(),
1331 where_clause: None,
1332 return_clause: ReturnClause {
1333 distinct: crate::ast::DistinctQualifier::None,
1334 items: return_items,
1335 location: Location::default(),
1336 },
1337 group_clause: None,
1338 having_clause: None,
1339 order_clause: None,
1340 limit_clause: None,
1341 location: Location::default(),
1342 };
1343

Calls 5

VariableClass · 0.85
cloneMethod · 0.80
insertMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected