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<'_>)
| 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 |
no test coverage detected