From 275db65d01703f576a6f2f80f4ab95653d17c92d Mon Sep 17 00:00:00 2001 From: discord9 Date: Tue, 27 Oct 2026 17:36:13 +0800 Subject: [PATCH] fix(promql): keep topk over aggregates on the merged-aggregate route The global selection claims only a root ranking over a series-local prefix. A topk over a read-across-series input belongs to the AggregateFinalize split, so stating that in the admission predicate keeps it there instead of declining the whole query. Provenance now rides on the shared evaluated frame packer: it appends its two columns after the packed batch instead of rebuilding the frame itself, so the frame layout stays in one place. Signed-off-by: discord9 --- src/promql/src/extension_plan/fused_series.rs | 17 +++++++---------- src/query/src/promql/planner/native.rs | 4 ++-- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/promql/src/extension_plan/fused_series.rs b/src/promql/src/extension_plan/fused_series.rs index fd3fe54aa1f..c6f9ead24e1 100644 --- a/src/promql/src/extension_plan/fused_series.rs +++ b/src/promql/src/extension_plan/fused_series.rs @@ -476,8 +476,7 @@ impl UserDefinedLogicalNodeCore for FusedSeries { self.promql, render_partial_fold(op) ), - None if self.format.is_frame() => - { + None if self.format.is_frame() => { write!(f, "FusedSeries: {} (output: series_frame)", self.promql) } None => write!(f, "FusedSeries: {}", self.promql), @@ -998,10 +997,7 @@ impl FusedSeriesExec { partial_fold: Option, format: FusedOutputFormat, ) -> DataFusionResult { - if partial_fold.is_none() - && format.is_frame() - && inputs.len() > 1 - { + if partial_fold.is_none() && format.is_frame() && inputs.len() > 1 { return Err(DataFusionError::Plan( "FusedSeries SeriesFrame output does not yet support multiple sources".into(), )); @@ -1026,6 +1022,7 @@ impl FusedSeriesExec { "FusedSeries partial fold requires one raw source and a per-series prefix".into(), )); } + let frame_schema = if partial_fold.is_none() && format.is_frame() { let evaluated = evaluated_output(&tree)?; let declared = if format == FusedOutputFormat::SeriesFrameWithProvenance { @@ -1735,11 +1732,11 @@ impl Stream for ProvenanceStream { self.producer; rows ])) as ArrayRef); - columns.push(Arc::new( - datafusion::arrow::array::UInt64Array::from_iter_values( + columns.push( + Arc::new(datafusion::arrow::array::UInt64Array::from_iter_values( self.next_ordinal..end, - ), - ) as ArrayRef); + )) as ArrayRef, + ); self.next_ordinal = end; match RecordBatch::try_new(self.schema.clone(), columns) { Ok(batch) => Poll::Ready(Some(Ok(batch))), diff --git a/src/query/src/promql/planner/native.rs b/src/query/src/promql/planner/native.rs index 38d686ac7c0..5d074e82582 100644 --- a/src/query/src/promql/planner/native.rs +++ b/src/query/src/promql/planner/native.rs @@ -589,8 +589,8 @@ impl PromPlanner { &root.expr, NativeExpr::Vector { op: BoundVectorOp::TopK { .. }, - .. - } + input + } if !reads_across_series(input) ); let ranked_fields = series_schema .fields