fix(promql): drop retained samples when an anchored window is skipped

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
Dennis Zhuang
2026-10-18 01:24:00 +08:00
parent a19e8cbd46
commit 72b06dc730
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -468,7 +468,8 @@ impl RangeEvaluator {
for field in &mut self.fields {
// After the last window, samples are still ingested so that the overflow and
// histogram checks do not depend on how the series is chunked, but none are kept.
if state.cursor == points_read {
// An anchored selector can skip past the one point it reads.
if state.cursor >= points_read {
field.head = field.timestamps.len();
}
field.timestamps.drain(..field.head);
+19
View File
@@ -1182,3 +1182,22 @@ fn rejects_a_subquery_grid_longer_than_u64() {
Err(DataFusionError::Plan(_))
));
}
/// An anchored window that ends before the series starts skips past the one point it reads;
/// later chunks must not pile up either.
#[test]
fn anchored_window_before_the_series_retains_nothing() {
let window = RangeWindow {
range_ms: 10,
offset_ms: 0,
anchor_ms: Some(5),
};
let mut evaluator = probe_evaluator(1, grid(100, 10, 3), window);
for chunk_index in 0..100 {
let rows: Vec<Row> = (0..100)
.map(|row| (50 + chunk_index * 100 + row, vec![Some(1.0)]))
.collect();
evaluator.push(&chunk(&rows, 1, 0, false)).unwrap();
assert!(evaluator.fields[0].timestamps.len() <= 100);
}
}