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

Function strip_table_qualifier

nodedb-sql/src/planner/ast_helpers.rs:53–82  ·  view source on GitHub ↗

Walk an expression and replace every `table.col` compound identifier where `table == qualifier` with a bare `col` identifier. Lets target-side predicates like `t.score > 15` be evaluated against documents that store fields without a table qualifier.

(expr: &ast::Expr, qualifier: &str)

Source from the content-addressed store, hash-verified

51/// predicates like `t.score > 15` be evaluated against documents that store
52/// fields without a table qualifier.
53pub fn strip_table_qualifier(expr: &ast::Expr, qualifier: &str) -> ast::Expr {
54 match expr {
55 ast::Expr::CompoundIdentifier(parts) if parts.len() == 2 => {
56 if normalize_ident(&parts[0]) == qualifier {
57 ast::Expr::Identifier(parts[1].clone())
58 } else {
59 expr.clone()
60 }
61 }
62 ast::Expr::BinaryOp { left, op, right } => ast::Expr::BinaryOp {
63 left: Box::new(strip_table_qualifier(left, qualifier)),
64 op: op.clone(),
65 right: Box::new(strip_table_qualifier(right, qualifier)),
66 },
67 ast::Expr::UnaryOp { op, expr: inner } => ast::Expr::UnaryOp {
68 op: *op,
69 expr: Box::new(strip_table_qualifier(inner, qualifier)),
70 },
71 ast::Expr::Nested(inner) => {
72 ast::Expr::Nested(Box::new(strip_table_qualifier(inner, qualifier)))
73 }
74 ast::Expr::IsNull(inner) => {
75 ast::Expr::IsNull(Box::new(strip_table_qualifier(inner, qualifier)))
76 }
77 ast::Expr::IsNotNull(inner) => {
78 ast::Expr::IsNotNull(Box::new(strip_table_qualifier(inner, qualifier)))
79 }
80 other => other.clone(),
81 }
82}
83
84/// Strip `qualifier.` from all compound identifiers in `expr`, then convert
85/// the result to `Vec<Filter>` via `convert_where_to_filters`.

Callers 1

Calls 3

normalize_identFunction · 0.85
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected