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

Function split_equality_from_expr

nodedb-sql/src/engine_rules/mod.rs:316–335  ·  view source on GitHub ↗

Return `(column, literal, residual_expr)` for an equality found anywhere in a right-leaning AND conjunction tree, or `None` if no bare column-equals-literal predicate exists. The residual preserves every sibling conjunct in their original order; `None` means the expression was a bare equality with nothing left behind.

(expr: &SqlExpr)

Source from the content-addressed store, hash-verified

314/// every sibling conjunct in their original order; `None` means the
315/// expression was a bare equality with nothing left behind.
316fn split_equality_from_expr(expr: &SqlExpr) -> Option<(String, SqlValue, Option<SqlExpr>)> {
317 // Gather the conjuncts of a top-level AND chain left-to-right.
318 let mut conjuncts: Vec<SqlExpr> = Vec::new();
319 flatten_and(expr, &mut conjuncts);
320
321 // Find the first conjunct that is a bare column-equals-literal.
322 let eq_idx = conjuncts.iter().position(is_column_eq_literal)?;
323 let eq = conjuncts.remove(eq_idx);
324 let (col, lit) = match eq {
325 SqlExpr::BinaryOp { left, op, right } => match (*left, op, *right) {
326 (SqlExpr::Column { name, .. }, BinaryOp::Eq, SqlExpr::Literal(v)) => (name, v),
327 (SqlExpr::Literal(v), BinaryOp::Eq, SqlExpr::Column { name, .. }) => (name, v),
328 _ => return None,
329 },
330 _ => return None,
331 };
332
333 let residual = rebuild_and(conjuncts);
334 Some((col, lit, residual))
335}
336
337/// Append every leaf of a right-leaning `AND` tree to `out`. Non-AND
338/// expressions are a single leaf.

Callers 1

Calls 4

flatten_andFunction · 0.85
rebuild_andFunction · 0.85
iterMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected