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

Function eval

nodedb/src/control/promql/evaluator/mod.rs:96–153  ·  view source on GitHub ↗
(ctx: &EvalContext, expr: &Expr)

Source from the content-addressed store, hash-verified

94}
95
96pub(crate) fn eval(ctx: &EvalContext, expr: &Expr) -> Result<Value, PromqlError> {
97 match expr {
98 Expr::Scalar(v) => Ok(Value::Scalar(*v, ctx.timestamp_ms)),
99 Expr::StringLiteral(_) => Err(PromqlError::TypeError {
100 context: "evaluation".to_string(),
101 detail: "string literals not supported in evaluation".to_string(),
102 }),
103 Expr::VectorSelector {
104 name,
105 matchers,
106 offset,
107 } => selector::eval_vector_selector(ctx, name.as_deref(), matchers, *offset),
108 Expr::MatrixSelector { selector, range } => {
109 selector::eval_matrix_selector(ctx, selector, *range)
110 }
111 Expr::Paren(inner) => eval(ctx, inner),
112 Expr::Negate(inner) => {
113 let val = eval(ctx, inner)?;
114 Ok(helpers::negate_value(val, ctx.timestamp_ms))
115 }
116 Expr::BinaryOp {
117 op,
118 lhs,
119 rhs,
120 return_bool,
121 ..
122 } => {
123 let l = eval(ctx, lhs)?;
124 let r = eval(ctx, rhs)?;
125 binary::eval_binary_op(*op, l, r, *return_bool, ctx.timestamp_ms)
126 }
127 Expr::Aggregate {
128 op,
129 expr: inner,
130 param,
131 grouping,
132 } => {
133 let val = eval(ctx, inner)?;
134 let p = match param {
135 Some(p) => {
136 if let Value::Scalar(v, _) = eval(ctx, p)? {
137 Some(v)
138 } else {
139 None
140 }
141 }
142 None => None,
143 };
144 aggregate::eval_aggregation(*op, val, p, grouping, ctx.timestamp_ms)
145 }
146 Expr::Call { func, args } => call::eval_call(ctx, func, args),
147 Expr::Subquery {
148 expr: inner,
149 range,
150 step,
151 } => eval_subquery(ctx, inner, *range, *step),
152 }
153}

Callers 13

evaluate_instantFunction · 0.70
evaluate_rangeFunction · 0.70
eval_subqueryFunction · 0.70
eval_callFunction · 0.70
eval_clampFunction · 0.70
eval_clamp_minFunction · 0.70
eval_clamp_maxFunction · 0.70
eval_absentFunction · 0.70
eval_label_replaceFunction · 0.70
eval_label_joinFunction · 0.70
eval_histogram_quantileFunction · 0.70
eval_string_argFunction · 0.70

Calls 8

eval_vector_selectorFunction · 0.85
eval_matrix_selectorFunction · 0.85
negate_valueFunction · 0.85
eval_aggregationFunction · 0.85
eval_callFunction · 0.85
eval_subqueryFunction · 0.85
to_stringMethod · 0.80
eval_binary_opFunction · 0.70

Tested by

no test coverage detected