mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-23 03:04:02 +00:00
fix(promql): drop retained samples when an anchored window is skipped
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user