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

Function extract_right_operand

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

Extract the right operand after `<->`: ARRAY[...], $param, or identifier. Returns (operand_text, consumed_length).

(after: &str)

Source from the content-addressed store, hash-verified

49/// Extract the right operand after `<->`: ARRAY[...], $param, or identifier.
50/// Returns (operand_text, consumed_length).
51fn extract_right_operand(after: &str) -> Option<(String, usize)> {
52 let trimmed = after.trim_start();
53 let upper = trimmed.to_uppercase();
54
55 if upper.starts_with("ARRAY[") {
56 let mut depth = 0;
57 for (i, c) in trimmed.char_indices() {
58 match c {
59 '[' => depth += 1,
60 ']' => {
61 depth -= 1;
62 if depth == 0 {
63 return Some((trimmed[..=i].to_string(), i + 1));
64 }
65 }
66 _ => {}
67 }
68 }
69 None
70 } else if trimmed.starts_with('$') {
71 let end = trimmed
72 .find(|c: char| !c.is_ascii_alphanumeric() && c != '_' && c != '$')
73 .unwrap_or(trimmed.len());
74 Some((trimmed[..end].to_string(), end))
75 } else {
76 let end = trimmed
77 .find(|c: char| !c.is_ascii_alphanumeric() && c != '_' && c != '.')
78 .unwrap_or(trimmed.len());
79 if end == 0 {
80 return None;
81 }
82 Some((trimmed[..end].to_string(), end))
83 }
84}
85
86/// Rewrite all occurrences of `expr <=> expr` to `vector_cosine_distance(expr, expr)`.
87///

Callers 1

rewrite_binary_opFunction · 0.85

Calls 3

to_stringMethod · 0.80
findMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected