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

Method eval_scope

nodedb-query/src/expr/eval.rs:92–176  ·  view source on GitHub ↗

Shared walker: one match, one recursion scheme, parameterised by the row-scope so `eval` and `eval_with_old` can't drift out of sync.

(&self, scope: &RowScope<'_>)

Source from the content-addressed store, hash-verified

90 /// Shared walker: one match, one recursion scheme, parameterised by the
91 /// row-scope so `eval` and `eval_with_old` can't drift out of sync.
92 fn eval_scope(&self, scope: &RowScope<'_>) -> Value {
93 match self {
94 SqlExpr::Column(name) => scope.column(name),
95 SqlExpr::OldColumn(name) => scope.old_column(name),
96 SqlExpr::ExcludedColumn(name) => scope.excluded_column(name),
97
98 SqlExpr::Literal(v) => v.clone(),
99
100 SqlExpr::BinaryOp { left, op, right } => {
101 let l = left.eval_scope(scope);
102 let r = right.eval_scope(scope);
103 eval_binary_op(&l, *op, &r)
104 }
105
106 SqlExpr::Negate(inner) => {
107 let v = inner.eval_scope(scope);
108 if let Some(b) = v.as_bool() {
109 Value::Bool(!b)
110 } else {
111 match value_to_f64(&v, false) {
112 Some(n) => to_value_number(-n),
113 None => Value::Null,
114 }
115 }
116 }
117
118 SqlExpr::Function { name, args } => {
119 let evaluated: Vec<Value> = args.iter().map(|a| a.eval_scope(scope)).collect();
120 crate::functions::eval_function(name, &evaluated)
121 }
122
123 SqlExpr::Cast { expr, to_type } => {
124 let v = expr.eval_scope(scope);
125 crate::cast::eval_cast(&v, to_type)
126 }
127
128 SqlExpr::Case {
129 operand,
130 when_thens,
131 else_expr,
132 } => {
133 let op_val = operand.as_ref().map(|e| e.eval_scope(scope));
134 for (when_expr, then_expr) in when_thens {
135 let when_val = when_expr.eval_scope(scope);
136 let matches = match &op_val {
137 Some(ov) => coerced_eq(ov, &when_val),
138 None => is_truthy(&when_val),
139 };
140 if matches {
141 return then_expr.eval_scope(scope);
142 }
143 }
144 match else_expr {
145 Some(e) => e.eval_scope(scope),
146 None => Value::Null,
147 }
148 }
149

Callers 3

evalMethod · 0.80
eval_with_oldMethod · 0.80
eval_with_excludedMethod · 0.80

Calls 15

value_to_f64Function · 0.85
to_value_numberFunction · 0.85
eval_functionFunction · 0.85
eval_castFunction · 0.85
old_columnMethod · 0.80
excluded_columnMethod · 0.80
collectMethod · 0.80
eval_binary_opFunction · 0.70
coerced_eqFunction · 0.50
is_truthyFunction · 0.50
columnMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected