From 3bedb09d6134a692efc874c61cefd35393e8a902 Mon Sep 17 00:00:00 2001 From: discord9 <55937128+discord9@users.noreply.github.com> Date: Tue, 20 Oct 2026 16:23:10 +0800 Subject: [PATCH] fix(promql): render a grouping as the shape it was bound as MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tree now binds an aggregate's grouping as `Grouping::{By, Without}` (#9723), so `label_list(&op.group)` no longer type-checks: the argument is a `Grouping`, and the function takes `&[Arc]`. This is production code, not a test helper, so the merged stack would not build. Rendering on the `By`/ `Without` shape fixes more than the type error: both were printed as `by [... ]`, which would show `by(job)` and `without(job)` — two different queries over the same label list — as the same query. A `without` aggregate now reads `sum without [job] complete`, and `a_without_grouping_does_not_read_as_by` pins it. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> --- src/promql/src/native/display.rs | 13 ++++++-- src/promql/src/native/display/tests.rs | 42 ++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/promql/src/native/display.rs b/src/promql/src/native/display.rs index 928e00e6ee9..7e0e82c2b5e 100644 --- a/src/promql/src/native/display.rs +++ b/src/promql/src/native/display.rs @@ -28,7 +28,8 @@ use datatypes::series::time::EvalGrid; use crate::map::MathOp; use crate::native::metrics::{self, NodePath}; use crate::native::plan::{ - AggregateKind, AggregateStage, BoundWindow, NativeExpr, NativeNode, NativeTree, NativeType, + AggregateKind, AggregateStage, BoundWindow, Grouping, NativeExpr, NativeNode, NativeTree, + NativeType, }; use crate::range_eval::RangeFunction; use crate::vector_match::{BinaryOp, Cardinality, MatchingLabels}; @@ -102,11 +103,17 @@ fn describe(node: &NativeNode) -> String { ops.join(", ") } NativeExpr::Aggregate { op, .. } => format!( - "{} by [{}] {}", + "{} {} [{}] {}", match op.kind { AggregateKind::Sum => "sum", }, - label_list(&op.group), + match &op.group { + Grouping::By(_) => "by", + Grouping::Without(_) => "without", + }, + label_list(match &op.group { + Grouping::By(labels) | Grouping::Without(labels) => labels, + }), match op.stage { AggregateStage::Complete => "complete", AggregateStage::Partial => "partial", diff --git a/src/promql/src/native/display/tests.rs b/src/promql/src/native/display/tests.rs index 2c30ab6cb21..8166bad3c98 100644 --- a/src/promql/src/native/display/tests.rs +++ b/src/promql/src/native/display/tests.rs @@ -20,7 +20,7 @@ use datatypes::series::time::{EvalGrid, GridSpec}; use super::super::plan::{ AggregateKind, AggregateStage, BoundAggregate, BoundInput, BoundInstant, BoundMap, BoundScalar, - BoundWindow, NativeExpr, NativeNode, NativeTree, NativeType, + BoundWindow, Grouping, NativeExpr, NativeNode, NativeTree, NativeType, }; use crate::map::MathOp; use crate::range_eval::{RangeFunction, RangeWindow}; @@ -286,7 +286,7 @@ fn an_aggregate_and_a_binary_name_their_binding() { )), op: BoundAggregate { kind: AggregateKind::Sum, - group: Arc::new(["job".into()]), + group: Grouping::By(Arc::new(["job".into()])), stage: AggregateStage::Complete, }, }, @@ -340,3 +340,41 @@ fn an_aggregate_and_a_binary_name_their_binding() { ]) ); } + +/// A `without` grouping reads as `without [...]`, not as `by [...]`. +/// +/// The two are different queries over the same label list: `by(job)` keeps `job` and drops the +/// rest, `without(job)` drops `job` and keeps the rest. A rendering that spelled both `by` would +/// show two different queries as one. +#[test] +fn a_without_grouping_does_not_read_as_by() { + let out = grid(0, 60_000, 4); + let aggregate = NativeNode { + expr: NativeExpr::Aggregate { + input: Box::new(window_over( + raw_input(), + RangeFunction::Rate, + 300_000, + 0, + None, + Arc::clone(&out), + )), + op: BoundAggregate { + kind: AggregateKind::Sum, + group: Grouping::Without(Arc::new(["job".into()])), + stage: AggregateStage::Complete, + }, + }, + output: evaluated(Arc::clone(&out)), + }; + let tree = NativeTree::try_new(aggregate).unwrap(); + assert_eq!( + tree.to_string(), + shown(&[ + "NativeTree", + " root Aggregate sum without [job] complete", + " input Window rate [300000ms] offset 0 anchor - on grid 0/60000x4", + " input Input raw samples", + ]) + ); +}