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

Function eval_binary_op

nodedb/src/control/promql/evaluator/binary.rs:12–53  ·  view source on GitHub ↗
(
    op: BinOp,
    lhs: Value,
    rhs: Value,
    return_bool: bool,
    ts: i64,
)

Source from the content-addressed store, hash-verified

10use super::helpers::match_key;
11
12pub 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
55fn eval_vector_binop(
56 op: BinOp,

Callers 1

evalFunction · 0.70

Calls 6

apply_binopFunction · 0.85
eval_vector_binopFunction · 0.85
collectMethod · 0.80
to_stringMethod · 0.80
iterMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected