From abb55be608447de3d3050c0378536fcc8fa6b70a Mon Sep 17 00:00:00 2001 From: Dennis Zhuang Date: Thu, 22 Oct 2026 14:05:38 +0800 Subject: [PATCH] refactor(promql): follow the Vector rename in the compiler Signed-off-by: Dennis Zhuang --- src/query/src/promql/native_compile.rs | 26 ++++++++++---------- src/query/src/promql/native_compile/tests.rs | 6 ++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/query/src/promql/native_compile.rs b/src/query/src/promql/native_compile.rs index f731c571427..981fbff54bd 100644 --- a/src/query/src/promql/native_compile.rs +++ b/src/query/src/promql/native_compile.rs @@ -30,7 +30,7 @@ //! which become `Input` (raw samples) → `Instant` (the last sample within the statement's lookback), //! `Input` (raw samples) → `Window` (the range function over the statement's grid) and //! `` → `Map` (a pointwise math function over what its argument evaluates to), and -//! `` → `Select` (a sort or `absent`, which read the whole vector). A +//! `` → `Vector` (a sort or `absent`, which read the whole vector). A //! selector may carry `offset` in either selection shape and, in the window shape, an `@` anchor. //! Everything else is a [`DataFusionError::NotImplemented`] that names what was found and quotes the //! shapes above, because rejecting a query the compiler does not understand is the only honest @@ -61,7 +61,7 @@ use datatypes::series::time::{EvalGrid, GridSpec}; use datatypes::series::{MetricName, SeriesOrdering}; use promql::map::{ArithmeticOp, MathOp}; use promql::native::plan::{ - BoundInput, BoundInstant, BoundMap, BoundSelect, BoundWindow, NativeExpr, NativeNode, + BoundInput, BoundInstant, BoundMap, BoundVectorOp, BoundWindow, NativeExpr, NativeNode, NativeTree, NativeType, }; use promql::range_eval::{RangeFunction, RangeWindow}; @@ -174,8 +174,8 @@ fn compile_call(context: &Context, call: &Call) -> Result { if let Some(signature) = range_signature(func.name) { return window_call(context, func.name, signature, &args.args); } - if let Some((op, vector)) = select_op(func.name, &args.args)? { - return select_call(context, func.name, op, vector); + if let Some((op, vector)) = vector_op(func.name, &args.args)? { + return vector_call(context, func.name, op, vector); } // The name is looked up before the call's arguments are read, so a name this compiler has no // kernel for is refused as such whichever arguments it was given: `pi()` and `time()` have no @@ -257,11 +257,11 @@ fn map_call(context: &Context, name: &str, op: MathOp, vector: &PromExpr) -> Res }) } -/// Wraps the selection `op` over the value of `vector`, which keeps its type as a map does. -fn select_call( +/// Wraps the vector operation `op` over the value of `vector`, which keeps its type as a map does. +fn vector_call( context: &Context, name: &str, - op: BoundSelect, + op: BoundVectorOp, vector: &PromExpr, ) -> Result { if vector.value_type() != ValueType::Vector { @@ -274,7 +274,7 @@ fn select_call( let input = compile_expr(context, vector)?; let output = input.output.clone(); Ok(NativeNode { - expr: NativeExpr::Select { + expr: NativeExpr::Vector { input: Box::new(input), op, }, @@ -282,12 +282,12 @@ fn select_call( }) } -/// The selection a sort or `absent` binds, and the vector it reads, or `None` when `name` is +/// The vector operation a sort or `absent` binds, and the vector it reads, or `None` when `name` is /// neither. -fn select_op<'a>( +fn vector_op<'a>( name: &str, arguments: &'a [Box], -) -> Result> { +) -> Result> { let order = match name { "sort" => Some(SortOrder::Asc), "sort_desc" => Some(SortOrder::Desc), @@ -300,7 +300,7 @@ fn select_op<'a>( ))); }; let labels = absent_labels_of(vector)?; - return Ok(Some((BoundSelect::Absent { labels }, vector))); + return Ok(Some((BoundVectorOp::Absent { labels }, vector))); } _ => return Ok(None), }; @@ -334,7 +334,7 @@ fn select_op<'a>( } } }; - Ok(Some((BoundSelect::Sort(order), vector))) + Ok(Some((BoundVectorOp::Sort(order), vector))) } /// The labels `absent(expr)` answers with, as Prometheus `createLabelsForAbsentFunction` derives diff --git a/src/query/src/promql/native_compile/tests.rs b/src/query/src/promql/native_compile/tests.rs index f4d4b990d58..53adbcb0ea1 100644 --- a/src/query/src/promql/native_compile/tests.rs +++ b/src/query/src/promql/native_compile/tests.rs @@ -1160,13 +1160,13 @@ fn a_math_function_over_a_non_vector_argument_is_refused_and_names_it() { } } -/// The sorts and `absent` bind a selection over the vector they are given. `absent` derives its +/// The sorts and `absent` bind a vector operation over the vector they are given. `absent` derives its /// labels from the selector's matchers as Prometheus does: the first equality of a name sets the /// label and any other matcher of it removes it, the matchers that accept a missing label read /// last; `__name__` and the table-choosing matchers are not labels, and any expression other than /// a selector answers without labels. #[test] -fn sorts_and_absent_bind_a_selection() { +fn sorts_and_absent_bind_a_vector_operation() { let cases = [ ("sort(x)", "sort"), ("sort_desc(rate(x[5m]))", "sort_desc"), @@ -1192,6 +1192,6 @@ fn sorts_and_absent_bind_a_selection() { .unwrap_or_else(|error| panic!("`{query}` was refused: {error}")); let display = tree.to_string(); let root = display.lines().nth(1).expect("a compiled tree has a root"); - assert_eq!(root, format!(" root Select {op}"), "`{query}`"); + assert_eq!(root, format!(" root Vector {op}"), "`{query}`"); } }