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

Function extract_left_operand

nodedb-sql/src/parser/preprocess/vector_ops.rs:18–35  ·  view source on GitHub ↗

Extract the left operand before `<->`: a column name or dotted path.

(before: &str)

Source from the content-addressed store, hash-verified

16
17/// Extract the left operand before `<->`: a column name or dotted path.
18fn extract_left_operand(before: &str) -> Option<String> {
19 // Determine what the effective "before" text is by looking only at the
20 // last Text segment — the operand cannot span across a quoted literal.
21 let text_before = last_text_segment(before);
22 let trimmed = text_before.trim_end();
23 let start = trimmed
24 .rfind(|c: char| !c.is_ascii_alphanumeric() && c != '_' && c != '.')
25 .map(|p| p + 1)
26 .unwrap_or(0);
27 let ident = &trimmed[start..];
28 if ident.is_empty() {
29 return None;
30 }
31 // Reconstruct including the prefix text up to the ident within `before`.
32 // We need the ident string only (the caller uses its length for offset math
33 // and only the text content for the rewrite).
34 Some(ident.to_string())
35}
36
37/// Return the content of the last `Text` segment in `sql`, or the whole
38/// string if there are no non-text segments.

Callers 1

rewrite_binary_opFunction · 0.85

Calls 3

last_text_segmentFunction · 0.85
to_stringMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected