(
op: BinOp,
lhs: Value,
rhs: Value,
return_bool: bool,
ts: i64,
)
| 10 | use super::helpers::match_key; |
| 11 | |
| 12 | pub fn eval_binary_op( |
| 13 | op: BinOp, |
| 14 | lhs: Value, |
| 15 | rhs: Value, |
| 16 | return_bool: bool, |
| 17 | ts: i64, |
| 18 | ) -> Result<Value, PromqlError> { |
| 19 | match (&lhs, &rhs) { |
| 20 | (Value::Scalar(a, _), Value::Scalar(b, _)) => { |
| 21 | Ok(Value::Scalar(apply_binop(op, *a, *b, return_bool), ts)) |
| 22 | } |
| 23 | (Value::Vector(vec), Value::Scalar(s, _)) => { |
| 24 | let result: Vec<InstantSample> = vec |
| 25 | .iter() |
| 26 | .map(|v| InstantSample { |
| 27 | labels: v.labels.clone(), |
| 28 | value: apply_binop(op, v.value, *s, return_bool), |
| 29 | timestamp_ms: v.timestamp_ms, |
| 30 | }) |
| 31 | .collect(); |
| 32 | Ok(Value::Vector(result)) |
| 33 | } |
| 34 | (Value::Scalar(s, _), Value::Vector(vec)) => { |
| 35 | let result: Vec<InstantSample> = vec |
| 36 | .iter() |
| 37 | .map(|v| InstantSample { |
| 38 | labels: v.labels.clone(), |
| 39 | value: apply_binop(op, *s, v.value, return_bool), |
| 40 | timestamp_ms: v.timestamp_ms, |
| 41 | }) |
| 42 | .collect(); |
| 43 | Ok(Value::Vector(result)) |
| 44 | } |
| 45 | (Value::Vector(left), Value::Vector(right)) => { |
| 46 | eval_vector_binop(op, left, right, return_bool, ts) |
| 47 | } |
| 48 | _ => Err(PromqlError::TypeError { |
| 49 | context: "binary op".to_string(), |
| 50 | detail: "unsupported operation between matrix types".to_string(), |
| 51 | }), |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | fn eval_vector_binop( |
| 56 | op: BinOp, |
no test coverage detected