mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 13:44:03 +00:00
fix(promql): render a grouping as the shape it was bound as
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<str>]`. 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>
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user