MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / left_join_rows

Function left_join_rows

nodedb/src/engine/graph/pattern/executor/mod.rs:313–362  ·  view source on GitHub ↗

LEFT JOIN: merge clause results with existing rows.

(
    input: &[BindingRow],
    clause_rows: &[BindingRow],
    clause: &MatchClause,
)

Source from the content-addressed store, hash-verified

311
312/// LEFT JOIN: merge clause results with existing rows.
313fn left_join_rows(
314 input: &[BindingRow],
315 clause_rows: &[BindingRow],
316 clause: &MatchClause,
317) -> Vec<BindingRow> {
318 let new_vars: Vec<String> = clause
319 .patterns
320 .iter()
321 .flat_map(|chain| {
322 chain.triples.iter().flat_map(|t| {
323 let mut vars = Vec::new();
324 if let Some(ref n) = t.src.name {
325 vars.push(n.clone());
326 }
327 if let Some(ref n) = t.dst.name {
328 vars.push(n.clone());
329 }
330 if let Some(ref n) = t.edge.name {
331 vars.push(n.clone());
332 }
333 vars
334 })
335 })
336 .collect();
337
338 let mut result = Vec::new();
339
340 for input_row in input {
341 let matches: Vec<&BindingRow> = clause_rows
342 .iter()
343 .filter(|cr| {
344 input_row
345 .iter()
346 .all(|(k, v)| cr.get(k).is_none_or(|cv| cv == v))
347 })
348 .collect();
349
350 if matches.is_empty() {
351 let mut row = input_row.clone();
352 for var in &new_vars {
353 row.entry(var.clone()).or_insert_with(|| "NULL".to_string());
354 }
355 result.push(row);
356 } else {
357 result.extend(matches.into_iter().cloned());
358 }
359 }
360
361 result
362}
363
364#[cfg(test)]
365mod tests {

Callers 1

execute_queryFunction · 0.85

Calls 10

collectMethod · 0.80
entryMethod · 0.80
to_stringMethod · 0.80
iterMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
allMethod · 0.45
getMethod · 0.45
is_emptyMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected