From e77bc0fb7d81276d4037ebbf420e21e2cce943fd Mon Sep 17 00:00:00 2001 From: discord9 <55937128+discord9@users.noreply.github.com> Date: Mon, 19 Oct 2026 13:28:18 +0800 Subject: [PATCH] perf(promql): hand out evaluated series as chunks instead of one buffered series `RangeEvaluator::push` evaluated every grid point a chunk completed, wrote the rows into its `GridSeriesBuilder`, and then returned `None` for a non-final chunk. A series therefore became visible only on its last chunk: the rows of every earlier chunk stayed buffered in the builder, and a consumer could not release or forward anything until the series ended. That is also why the fused node that evaluates raw samples could emit one batch per series and not per input chunk. `push` now returns the positions it finished as an `EvaluatedChunk`: the evaluated rows plus an `is_last` flag, addressed on the grid by an absolute `GridRange`. A consumer can forward a prefix while the series continues, and `is_last` is the only thing that closes the series. `evaluated.rs` holds that type and the rule it enforces, that a chunk is addressed on a grid. Two protocol points make streaming safe. Ranges of one series only increase, so concatenating the chunks of a series never reorders them. The closing chunk is handed out even when it holds no position, so a series whose remaining grid points have no value still reports that it ended rather than leaving a consumer waiting for input that will not come; previously those series returned `None` and ended silently. `push_series` likewise returns its one closing chunk. Tests fold the chunks of a series back into one series and compare that against the same brute-force reference and Prometheus UDF references as before, so the chunking is checked against the values, not against itself. The fold helper fails on a chunk after the closing chunk, and the golden range-function and mixed-histogram suites, which push one sample per chunk, go through it. Signed-off-by: discord9 Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> --- src/promql/src/evaluated.rs | 149 +++++++++++++++++ src/promql/src/lib.rs | 1 + src/promql/src/range_eval.rs | 97 +++++++++-- src/promql/src/range_eval/tests.rs | 251 ++++++++++++++++++++++------- 4 files changed, 424 insertions(+), 74 deletions(-) create mode 100644 src/promql/src/evaluated.rs diff --git a/src/promql/src/evaluated.rs b/src/promql/src/evaluated.rs new file mode 100644 index 00000000000..af5c7d1bd34 --- /dev/null +++ b/src/promql/src/evaluated.rs @@ -0,0 +1,149 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! One slice of an evaluated series, as evaluators hand it to their consumers. + +use datafusion::error::{DataFusionError, Result}; +use datatypes::series::samples::Series; +use datatypes::series::time::{GridRange, TimeAxis}; + +/// One slice of one evaluated series. +/// +/// The series' [`TimeAxis::Grid`] covers the positions this chunk has finished evaluating. Those +/// positions are absolute on the grid: a consumer that concatenates the chunks of a series never +/// reorders them, and never has to translate a chunk-local row number into a grid position. +/// +/// A series closes exactly once, on the chunk that carries [`EvaluatedChunk::is_last`]. A closed +/// prefix is always followed by a closing chunk, even when that chunk holds no values, so a +/// consumer can tell "nothing more at these positions" from "no more input". +#[derive(Debug)] +pub struct EvaluatedChunk { + /// The evaluated values, addressed on their absolute grid positions. + pub series: Series, + /// Whether this is the final chunk of this series. + pub is_last: bool, +} + +impl EvaluatedChunk { + /// Wraps `series`, checking that it is addressed on a grid. + pub fn try_new(series: Series, is_last: bool) -> Result { + if !matches!(series.time, TimeAxis::Grid(_)) { + return Err(DataFusionError::Execution( + "an evaluated chunk must be addressed on a grid".to_string(), + )); + } + Ok(Self { series, is_last }) + } + + /// The absolute grid range this chunk covers. + /// + /// Ranges of one series increase and never overlap. An empty range is meaningful: it reports + /// that the chunk closed a prefix of the grid without producing new values, which a consumer + /// needs in order to advance. + pub fn range(&self) -> &GridRange { + match &self.series.time { + TimeAxis::Grid(range) => range, + // `try_new` rejects anything else, and `series` is public, so a chunk built by struct + // literal is checked here rather than trusted. + _ => unreachable!("an evaluated chunk is always addressed on a grid"), + } + } +} + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use datatypes::arrow::array::Float64Array; + use datatypes::series::MetricName; + use datatypes::series::samples::{FieldSpec, Samples, Series, SeriesFields, SeriesSchema}; + use datatypes::series::time::{EvalGrid, GridRange, GridSpec, TimeAxis}; + + use super::EvaluatedChunk; + + fn grid() -> Arc { + Arc::new(EvalGrid::try_new(GridSpec::try_new(0, 60_000, 4).unwrap()).unwrap()) + } + + fn schema() -> SeriesSchema { + SeriesSchema { + fields: Arc::from([FieldSpec { name: "v0".into() }]), + eval_grid: Some(grid()), + } + } + + fn metric() -> MetricName { + MetricName::try_new(Some("requests".into()), Vec::new()).unwrap() + } + + /// `values` are the floats this chunk finished evaluating; `start` is their absolute offset. + fn chunk( + schema: &SeriesSchema, + start: usize, + values: Vec, + is_last: bool, + ) -> EvaluatedChunk { + let samples = Samples::from_float(Float64Array::from(values)); + let range = + GridRange::try_new(schema.eval_grid.clone().unwrap(), start, samples.len()).unwrap(); + let series = Series { + metric: metric(), + time: TimeAxis::Grid(range), + fields: SeriesFields::try_from_vec(vec![samples]).unwrap(), + }; + EvaluatedChunk::try_new(series, is_last).unwrap() + } + + /// A chunk without values is still a chunk: it is how a closed prefix is reported, and a + /// consumer needs it to tell "nothing more here" from "no more input". + #[test] + fn a_chunk_can_cover_no_positions() { + let schema = schema(); + let empty = Samples::from_float(Float64Array::from(Vec::::new())); + let range = GridRange::try_new(schema.eval_grid.clone().unwrap(), 4, 0).unwrap(); + assert!(range.is_empty()); + let series = Series { + metric: metric(), + time: TimeAxis::Grid(range), + fields: SeriesFields::try_from_vec(vec![empty]).unwrap(), + }; + let chunk = EvaluatedChunk::try_new(series, true).unwrap(); + assert!(chunk.range().is_empty()); + assert!(chunk.is_last); + } + + /// The range is absolute, so concatenating two chunks of one series never reorders them. + #[test] + fn a_range_is_absolute_on_its_grid() { + let schema = schema(); + let first = chunk(&schema, 0, vec![1.0, 2.0], false); + let second = chunk(&schema, 2, vec![3.0, 4.0], true); + assert_eq!((first.range().start(), first.range().len()), (0, 2)); + assert_eq!((second.range().start(), second.range().len()), (2, 2)); + assert!(!first.is_last); + assert!(second.is_last); + } + + /// A chunk that is not addressed on a grid cannot be indexed by a consumer. + #[test] + fn a_chunk_must_be_addressed_on_a_grid() { + let samples = Samples::from_float(Float64Array::from(vec![1.0])); + let series = Series { + metric: metric(), + time: TimeAxis::Explicit(datatypes::arrow::buffer::ScalarBuffer::from(vec![0i64])), + fields: SeriesFields::try_from_vec(vec![samples]).unwrap(), + }; + assert!(EvaluatedChunk::try_new(series, true).is_err()); + } +} diff --git a/src/promql/src/lib.rs b/src/promql/src/lib.rs index f4a4fca99c4..b8303cf648a 100644 --- a/src/promql/src/lib.rs +++ b/src/promql/src/lib.rs @@ -13,6 +13,7 @@ // limitations under the License. pub mod error; +pub mod evaluated; pub mod extension_plan; pub mod functions; mod go_sort; diff --git a/src/promql/src/range_eval.rs b/src/promql/src/range_eval.rs index 480f848321f..b026b70c636 100644 --- a/src/promql/src/range_eval.rs +++ b/src/promql/src/range_eval.rs @@ -18,15 +18,17 @@ use std::ops::Range; use std::sync::Arc; use common_query::prometheus::is_prometheus_stale_nan; +use datafusion::arrow::array::Float64Array; use datafusion::arrow::buffer::Buffer; use datafusion::error::{DataFusionError, Result}; use datatypes::series::MetricName; use datatypes::series::histogram::CounterResetHint; use datatypes::series::raw::RawSeriesChunk; -use datatypes::series::samples::{SampleRef, Series, SeriesFields, SeriesSchema}; -use datatypes::series::time::{EvalGrid, GridSpec, TimeAxis}; +use datatypes::series::samples::{SampleRef, Samples, Series, SeriesFields, SeriesSchema}; +use datatypes::series::time::{EvalGrid, GridRange, GridSpec, TimeAxis}; -use crate::grid_series::{GridSample, GridSeriesBuilder, METADATA_LABELS}; +use crate::evaluated::EvaluatedChunk; +use crate::grid_series::{GridSample, GridSeriesBuilder, METADATA_LABELS, external}; use crate::histogram_eval::float_histogram::FloatHistogram; mod function; @@ -105,9 +107,14 @@ pub(crate) type BatchKernel = Box, &mut Vec Result> { + pub fn push(&mut self, chunk: &RawSeriesChunk) -> Result> { if self.input_grid.is_some() { return Err(DataFusionError::Execution( "raw series chunk pushed to an evaluator of evaluated series".into(), @@ -502,15 +516,17 @@ impl RangeEvaluator { self.evaluate(Some( i128::from(last_ts) + i128::from(self.window.offset_ms), ))?; - return Ok(None); + return self.emit(false); } - self.finish_series() + self.close_series() } /// Evaluates one complete evaluated series, such as the inner result of a subquery: the /// value at each grid point is a sample at that time. Stale markers are kept as values, /// since the input is computed. - pub fn push_series(&mut self, series: &Series) -> Result> { + /// + /// The input arrives complete, so its result is one closing chunk. + pub fn push_series(&mut self, series: &Series) -> Result> { let TimeAxis::Grid(range) = &series.time else { return Err(DataFusionError::Execution( "evaluated range input must be a grid series".into(), @@ -534,18 +550,66 @@ impl RangeEvaluator { metric: series.metric.clone(), last_ts: 0, cursor: 0, + emitted_end: 0, }); self.ingest(&range.timestamps(), &series.fields, false)?; - self.finish_series() + self.close_series() } - fn finish_series(&mut self) -> Result> { + /// Evaluates the rest of the series of the last input chunk and closes it. + fn close_series(&mut self) -> Result> { self.evaluate(None)?; - let mut state = self.series.take().expect("set by the caller"); + let chunk = self.emit(true)?; + self.series = None; + Ok(chunk) + } + + /// Hands out the positions evaluated since the last chunk, if any. + /// + /// `is_last` closes the series, and then a chunk is always handed out: a consumer needs the + /// closing chunk to advance, and a series whose remaining points hold no values would + /// otherwise close silently. + fn emit(&mut self, is_last: bool) -> Result> { + let Some(state) = self.series.as_ref() else { + return Ok(None); + }; + let ended = state.emitted_end; + let mut metric = state.metric.clone(); if self.drops_metric_name { - state.metric.remove_all(&METADATA_LABELS); + metric.remove_all(&METADATA_LABELS); } - self.output.finish(state.metric) + let Some(series) = self.output.finish(metric)? else { + return if is_last { + self.empty_chunk(ended) + } else { + Ok(None) + }; + }; + let TimeAxis::Grid(range) = &series.time else { + unreachable!("the builder always emits a grid series") + }; + let emitted_end = range.start() + range.len(); + self.series + .as_mut() + .expect("checked at the entry of emit") + .emitted_end = emitted_end; + EvaluatedChunk::try_new(series, is_last).map(Some) + } + + /// A closing chunk without values, addressed after the last position handed out. + fn empty_chunk(&self, at: usize) -> Result> { + let state = self.series.as_ref().expect("checked by the caller"); + let mut metric = state.metric.clone(); + if self.drops_metric_name { + metric.remove_all(&METADATA_LABELS); + } + let empty = Samples::from_float(Float64Array::from(Vec::::new())); + let fields = SeriesFields::try_from_vec(vec![empty; self.output_schema.fields.len()]) + .map_err(external)?; + let time = GridRange::try_new(self.grid.clone(), at, 0).map_err(external)?; + let series = Series::try_new(&self.output_schema, metric, TimeAxis::Grid(time), fields) + .map_err(external)?; + EvaluatedChunk::try_new(series, true).map(Some) } /// Checks that the input did not end inside a series. @@ -584,6 +648,7 @@ impl RangeEvaluator { metric, last_ts: time[time.len() - 1], cursor: 0, + emitted_end: 0, }); } Some(state) => { diff --git a/src/promql/src/range_eval/tests.rs b/src/promql/src/range_eval/tests.rs index 40998a11eac..8dd20fee0a4 100644 --- a/src/promql/src/range_eval/tests.rs +++ b/src/promql/src/range_eval/tests.rs @@ -40,15 +40,16 @@ use super::{ CounterReset, FloatWindow, RangeEvaluator, RangeFunction, RangeWindow, WindowKernel, subquery_grid, }; +use crate::evaluated::EvaluatedChunk; use crate::functions::{ Changes, CountOverTime, IDelta, LastOverTime, MaxOverTime, MinOverTime, PresentOverTime, Resets, }; -use crate::grid_series::GridSeriesBuilder; use crate::grid_series::reference::{ Dense, GoldenCase, OwnedHistogram, assert_histogram_close, assert_series_eq, assert_series_eq_any_nan, close, expand, golden_cases, labels_of, metric_of, mixed_series, random_dense, special_value, }; +use crate::grid_series::{GridSample, GridSeriesBuilder}; use crate::histogram_eval::float_histogram::FloatHistogram; use crate::range_array::RangeArray; use crate::select::{LabelMatcher, MatchOp, absent, absent_labels}; @@ -197,6 +198,70 @@ fn random_chunks(rng: &mut StdRng, rows: &[Row], fields: usize, host: u64) -> Ve chunks } +/// The float values of a single-field series, in order. +fn floats(series: &Series) -> Vec { + let field = &series.fields.as_slice()[0]; + (0..field.len()) + .map(|index| match field.sample(index) { + SampleRef::Float(value) => value, + _ => panic!("expected a float"), + }) + .collect() +} + +/// Pushes every chunk of one series, keeping what the evaluator hands out on the way. +fn collect_chunks( + evaluator: &mut RangeEvaluator, + pieces: &[RawSeriesChunk], +) -> Vec { + pieces + .iter() + .flat_map(|piece| evaluator.push(piece).unwrap()) + .collect() +} + +/// Folds the chunks of one series back into one series, the way a consumer that keeps every value +/// would, and checks the chunk protocol: absolute increasing ranges, and one closing chunk last. +fn fold_chunks(chunks: &[EvaluatedChunk], schema: &Arc) -> Option { + let metric = chunks + .first() + .expect("a series always hands out its closing chunk") + .series + .metric + .clone(); + let mut builder = GridSeriesBuilder::try_new(schema.clone()).unwrap(); + let mut closing = false; + for chunk in chunks { + assert!(!closing, "a chunk follows the closing chunk"); + closing = chunk.is_last; + let range = chunk.range(); + let mut fields: Vec<_> = chunk + .series + .fields + .iter() + .map(|field| field.iter()) + .collect(); + for row in 0..range.len() { + let values: Vec<_> = fields + .iter_mut() + .map( + |field| match field.next().expect("the range length is checked") { + SampleRef::Missing => None, + SampleRef::Float(value) => Some(GridSample::Float(value)), + SampleRef::Histogram(view) => Some(GridSample::Histogram(Box::new( + FloatHistogram::try_from_view(&view).unwrap(), + ))), + }, + ) + .collect(); + // Positions only increase across chunks, so an overlap is an error here. + builder.push_samples(range.start() + row, &values).unwrap(); + } + } + assert!(closing, "the series never closed"); + builder.finish(metric).unwrap() +} + fn random_rows(rng: &mut StdRng, fields: usize) -> Vec { let missing = if rng.random_bool(0.3) { 0.0 } else { 0.15 }; let counter = rng.random_bool(0.5); @@ -454,14 +519,11 @@ fn evaluator_matches_brute_force_reference() { for host in 0..3 { let rows = random_rows(&mut rng, fields); let expected = reference(&rows, &grid, window, fields, true, step_invariant); - let mut result = None; - for piece in random_chunks(&mut rng, &rows, fields, host) { - assert!( - result.is_none(), - "seed {seed}: result before the last chunk" - ); - result = evaluator.push(&piece).unwrap(); - } + let chunks = collect_chunks( + &mut evaluator, + &random_chunks(&mut rng, &rows, fields, host), + ); + let result = fold_chunks(&chunks, evaluator.output_schema()); assert_series_eq(result.as_ref(), &expected, &metric(host)); } evaluator.finish().unwrap(); @@ -496,10 +558,11 @@ fn functions_match_range_udfs() { for host in 0..3 { let rows = random_rows(&mut rng, fields); let expected = udf_reference(function, &rows, &grid, window, fields, true); - let mut result = None; - for piece in random_chunks(&mut rng, &rows, fields, host) { - result = evaluator.push(&piece).unwrap(); - } + let chunks = collect_chunks( + &mut evaluator, + &random_chunks(&mut rng, &rows, fields, host), + ); + let result = fold_chunks(&chunks, evaluator.output_schema()); assert_series_eq(result.as_ref(), &expected, &output_metric(function, host)); } } @@ -691,14 +754,51 @@ fn empty_input_and_series_without_results() { }; probe_evaluator(1, grid(0, 10, 4), window).finish().unwrap(); + // A series whose samples all miss the grid still closes, on a chunk holding no positions. let mut evaluator = probe_evaluator(1, grid(0, 10, 4), window); let after_grid = chunk(&[(31, vec![Some(1.0)])], 1, 0, true); - assert!(evaluator.push(&after_grid).unwrap().is_none()); + let closed = evaluator + .push(&after_grid) + .unwrap() + .expect("a series closes"); + assert!(closed.is_last); + assert!(closed.range().is_empty()); let only_stale = chunk(&[(5, vec![Some(stale())])], 1, 1, true); - assert!(evaluator.push(&only_stale).unwrap().is_none()); + let closed = evaluator + .push(&only_stale) + .unwrap() + .expect("a series closes"); + assert!(closed.is_last); + assert!(closed.range().is_empty()); evaluator.finish().unwrap(); } +/// A series whose last sample is behind the end of the grid still closes, on a chunk holding no +/// positions: the remaining points have no values, and only the closing chunk tells the consumer +/// that the series is over rather than still waiting for input. +#[test] +fn a_series_that_ends_early_still_closes() { + let window = RangeWindow { + range_ms: 10, + offset_ms: 0, + anchor_ms: None, + }; + let mut evaluator = probe_evaluator(1, grid(0, 10, 5), window); + let first = chunk(&[(0, vec![Some(1.0)]), (10, vec![Some(2.0)])], 1, 0, false); + let handed = evaluator + .push(&first) + .unwrap() + .expect("the windows of the first two points are complete"); + assert!(!handed.is_last); + assert_eq!((handed.range().start(), handed.range().len()), (0, 2)); + + let last = chunk(&[(45, vec![Some(3.0)])], 1, 0, true); + let closed = evaluator.push(&last).unwrap().expect("a series closes"); + assert!(closed.is_last); + assert!(closed.range().is_empty()); + assert_eq!(closed.range().start(), 2); +} + #[test] fn rejects_invalid_parameters() { let zero_range = RangeWindow { @@ -859,7 +959,7 @@ fn histogram_samples_need_a_function_and_drop_stale_markers() { RangeFunction::CountOverTime, ) .unwrap(); - let series = evaluator.push(&piece).unwrap().unwrap(); + let series = evaluator.push(&piece).unwrap().unwrap().series; assert!(matches!( series.fields.as_slice()[0].sample(0), SampleRef::Float(count) if count == 1.0 @@ -968,14 +1068,15 @@ fn counter_resets_follow_the_window_and_survive_chunking() { .unwrap(); for (start, end) in pieces { let last = end == rows.len(); - let result = evaluator + if let Some(handed) = evaluator .push(&chunk(&rows[start..end], 2, 0, last)) - .unwrap(); - assert_eq!( - result.is_some(), - last, - "the series must finish on its last chunk" - ); + .unwrap() + { + assert_eq!( + handed.is_last, last, + "only the last chunk closes the series" + ); + } } evaluator }; @@ -1012,12 +1113,17 @@ fn counter_resets_follow_the_window_and_survive_chunking() { // index state of the first series may survive, so the second series reports exactly the same // windows and resets. recorded.lock().unwrap().clear(); - let mut result = None; for (start, end) in pieces { - assert!(result.is_none(), "a result before the last chunk"); - result = evaluator - .push(&chunk(&rows[start..end], 2, 1, end == rows.len())) - .unwrap(); + let closed = end == rows.len(); + if let Some(chunk) = evaluator + .push(&chunk(&rows[start..end], 2, 1, closed)) + .unwrap() + { + assert_eq!( + chunk.is_last, closed, + "only the last chunk closes the series" + ); + } } assert_eq!(*recorded.lock().unwrap(), recorded_of(&expected)); evaluator.finish().unwrap(); @@ -1160,20 +1266,23 @@ fn subquery_series_match_references() { ) .unwrap(); let expected = reference(&rows, &outer, window, fields, false, true); - assert_series_eq( - probe.push_series(&series).unwrap().as_ref(), - &expected, - &metric(seed), - ); + let evaluated = probe + .push_series(&series) + .unwrap() + .expect("the input closes"); + assert!(evaluated.is_last); + let result = fold_chunks(std::slice::from_ref(&evaluated), probe.output_schema()); + assert_series_eq(result.as_ref(), &expected, &metric(seed)); for function in udf_functions() { let mut evaluator = RangeEvaluator::try_new(&schema, outer.clone(), window, function).unwrap(); let expected = udf_reference(function, &rows, &outer, window, fields, false); - assert_series_eq( - evaluator.push_series(&series).unwrap().as_ref(), - &expected, - &output_metric(function, seed), - ); + let evaluated = evaluator + .push_series(&series) + .unwrap() + .expect("the input closes"); + let result = fold_chunks(std::slice::from_ref(&evaluated), evaluator.output_schema()); + assert_series_eq(result.as_ref(), &expected, &output_metric(function, seed)); } } } @@ -1316,14 +1425,16 @@ fn range_functions_match_prometheus() { let mut evaluator = RangeEvaluator::try_new(&raw_schema(1), grid, window, function).unwrap(); let split = rows.len() / 2; - let mut result = None; - if split > 0 { - evaluator.push(&chunk(&rows[..split], 1, 0, false)).unwrap(); - } - result = evaluator - .push(&chunk(&rows[split..], 1, 0, true)) - .unwrap() - .or(result); + let pieces = if split > 0 { + vec![ + chunk(&rows[..split], 1, 0, false), + chunk(&rows[split..], 1, 0, true), + ] + } else { + vec![chunk(&rows, 1, 0, true)] + }; + let chunks = collect_chunks(&mut evaluator, &pieces); + let result = fold_chunks(&chunks, evaluator.output_schema()); assert_series_eq_any_nan( result.as_ref(), &expected, @@ -1354,7 +1465,11 @@ fn rejects_double_exponential_smoothing_factors_outside_the_unit_interval() { }; // Like Prometheus, only a window holding a sample checks the factors. let outside = chunk(&[(100, vec![Some(1.0)])], 1, 0, true); - assert!(evaluator().push(&outside).unwrap().is_none()); + let closed = evaluator() + .push(&outside) + .unwrap() + .expect("a series closes"); + assert!(closed.range().is_empty()); evaluator().finish().unwrap(); let inside = chunk(&[(5, vec![Some(1.0)])], 1, 0, true); assert!(matches!( @@ -1404,7 +1519,7 @@ fn range_functions_drop_metadata_labels() { let mut evaluator = RangeEvaluator::try_new(&raw_schema(1), grid(2_000, 1_000, 1), window, function) .unwrap(); - let series = evaluator.push(&chunk).unwrap().unwrap(); + let series = evaluator.push(&chunk).unwrap().unwrap().series; assert_eq!(series.metric, expected, "{function:?}"); } } @@ -1428,7 +1543,11 @@ fn ts_of_extremum_moves_past_a_leading_nan() { let mut evaluator = RangeEvaluator::try_new(&raw_schema(1), grid(3_000, 1_000, 1), window, function) .unwrap(); - let series = evaluator.push(&chunk(&rows, 1, 0, true)).unwrap().unwrap(); + let series = evaluator + .push(&chunk(&rows, 1, 0, true)) + .unwrap() + .unwrap() + .series; assert_series_eq( Some(&series), &vec![vec![Some(expected)]], @@ -1480,7 +1599,11 @@ fn ts_of_last_over_time_reports_zero_for_negative_timestamps() { ] { let mut evaluator = RangeEvaluator::try_new(&raw_schema(1), grid(0, 1_000, 1), window, function).unwrap(); - let series = evaluator.push(&chunk(&rows, 1, 0, true)).unwrap().unwrap(); + let series = evaluator + .push(&chunk(&rows, 1, 0, true)) + .unwrap() + .unwrap() + .series; assert_series_eq( Some(&series), &vec![vec![Some(expected)]], @@ -1536,7 +1659,11 @@ fn quantile_picks_the_signed_zero_go_picks() { RangeFunction::QuantileOverTime(f64::from(k) / 19.0), ) .unwrap(); - let series = evaluator.push(&chunk(&rows, 1, 0, true)).unwrap().unwrap(); + let series = evaluator + .push(&chunk(&rows, 1, 0, true)) + .unwrap() + .unwrap() + .series; let SampleRef::Float(value) = series.fields.as_slice()[0].sample(0) else { panic!("expected a float"); }; @@ -1604,7 +1731,11 @@ fn anchored_predict_linear_regresses_around_each_point() { RangeFunction::PredictLinear(0.0), ) .unwrap(); - let series = evaluator.push(&chunk(&rows, 1, 0, true)).unwrap().unwrap(); + let series = evaluator + .push(&chunk(&rows, 1, 0, true)) + .unwrap() + .unwrap() + .series; let values: Vec<_> = (0..3) .map(|index| match series.fields.as_slice()[0].sample(index) { SampleRef::Float(value) => value, @@ -1746,7 +1877,12 @@ fn absent_over_time_is_absent_over_present_over_time() { RangeFunction::PresentOverTime, ) .unwrap(); - present.extend(evaluator.push(&chunk(&rows, 1, host as u64, true)).unwrap()); + let closed = evaluator + .push(&chunk(&rows, 1, host as u64, true)) + .unwrap() + .expect("the series closes"); + assert!(closed.is_last); + present.push(closed.series); } let schema = SeriesSchema { fields: raw_schema(1).fields, @@ -1852,10 +1988,9 @@ fn histogram_range_functions_match_prometheus() { let mut evaluator = RangeEvaluator::try_new(&raw_schema(1), case.grid.clone(), window, function) .unwrap(); - for chunk in mixed_chunks(&case, index, split) { - if let Some(series) = evaluator.push(&chunk).unwrap() { - actual.insert(labels_of(&series.metric), series); - } + let chunks = collect_chunks(&mut evaluator, &mixed_chunks(&case, index, split)); + if let Some(series) = fold_chunks(&chunks, evaluator.output_schema()) { + actual.insert(labels_of(&series.metric), series); } } let expected = case.outcome.as_ref().unwrap(); @@ -1933,7 +2068,7 @@ fn evaluated_histograms_drop_counter_reset_hints() { }; let mut evaluator = RangeEvaluator::try_new(&schema, grid(10, 10, 1), window, RangeFunction::Resets).unwrap(); - let result = evaluator.push_series(&series).unwrap().unwrap(); + let result = evaluator.push_series(&series).unwrap().unwrap().series; assert!(matches!( result.fields.as_slice()[0].sample(0), SampleRef::Float(resets) if resets == 0.0