mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 13:44:03 +00:00
refactor(promql): drop per-field clearing the evaluator never needs
Two review findings, both about code that does nothing. `finish_series` cleared every field after `evaluate(None)` returned. That loop is redundant: `evaluate` ends with either every point evaluated -- so `head` moved to the end and `advance` dropped the samples -- or no field holding a sample, and either way the fields are empty. It also did not clear `histograms`, which made it read as though it should. Removing it keeps the suite green, and `push` already documents that an evaluator is not reused after an error. `FieldSamples::clear` existed only for that loop. `overlapping_window_spans_chunks` used a `sum` kernel and never touched resets. Windows spanning chunks are already covered by `evaluator_matches_brute_force_reference`, which chunks randomly, and no mutation was caught only by this test. Its `sum` helper went with it. Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
@@ -124,8 +124,10 @@ struct FieldSamples {
|
||||
/// Native histogram samples, kept apart from the floats as Prometheus does.
|
||||
histograms: Vec<(i64, FloatHistogram)>,
|
||||
histogram_head: usize,
|
||||
/// Sequence number of `values[0]`. Absolute and monotonic, so a reset keeps its position
|
||||
/// when `head` samples are dropped instead of every index being renumbered.
|
||||
/// Sequence number of `values[0]`. Absolute and monotonic across the series this evaluator
|
||||
/// evaluates, so a reset keeps its position when `head` samples are dropped instead of every
|
||||
/// index being renumbered. An empty field holds the number of samples already dropped, which
|
||||
/// keeps positions increasing when the next series starts.
|
||||
base: u64,
|
||||
/// Resets between consecutive retained samples, ascending by position: exactly the ones a
|
||||
/// window over these samples can still contain. Maintained only for the counter-correcting
|
||||
@@ -204,14 +206,6 @@ impl FieldSamples {
|
||||
let count = self.resets[first..].partition_point(|reset| reset.position < end);
|
||||
&self.resets[first..first + count]
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
self.timestamps.clear();
|
||||
self.values.clear();
|
||||
self.head = 0;
|
||||
self.base = 0;
|
||||
self.resets.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl RangeEvaluator {
|
||||
@@ -373,9 +367,6 @@ impl RangeEvaluator {
|
||||
fn finish_series(&mut self) -> Result<Option<Series>> {
|
||||
self.evaluate(None)?;
|
||||
let mut state = self.series.take().expect("set by the caller");
|
||||
for field in &mut self.fields {
|
||||
field.clear();
|
||||
}
|
||||
if self.drops_metric_name {
|
||||
state.metric.remove_all(&METADATA_LABELS);
|
||||
}
|
||||
|
||||
@@ -89,10 +89,6 @@ fn scanned_resets(values: &[f64]) -> Vec<CounterReset> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn sum(window: FloatWindow<'_>) -> Option<f64> {
|
||||
Some(window.values.iter().sum())
|
||||
}
|
||||
|
||||
fn raw_schema(fields: usize) -> SeriesSchema {
|
||||
SeriesSchema {
|
||||
fields: (0..fields)
|
||||
@@ -510,26 +506,6 @@ fn functions_match_range_udfs() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlapping_window_spans_chunks() {
|
||||
let window = RangeWindow {
|
||||
range_ms: 15,
|
||||
offset_ms: 0,
|
||||
anchor_ms: None,
|
||||
};
|
||||
let kernel: WindowKernel = Box::new(sum);
|
||||
let mut evaluator =
|
||||
RangeEvaluator::with_kernel(&raw_schema(1), grid(10, 10, 3), window, kernel, true, true)
|
||||
.unwrap();
|
||||
let first = chunk(&[(5, vec![Some(1.0)]), (12, vec![Some(2.0)])], 1, 0, false);
|
||||
let second = chunk(&[(18, vec![Some(4.0)]), (25, vec![Some(8.0)])], 1, 0, true);
|
||||
assert!(evaluator.push(&first).unwrap().is_none());
|
||||
let series = evaluator.push(&second).unwrap();
|
||||
// Windows (-5, 10], (5, 20] and (15, 30].
|
||||
let expected = vec![vec![Some(1.0)], vec![Some(6.0)], vec![Some(12.0)]];
|
||||
assert_series_eq(series.as_ref(), &expected, &metric(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_input_and_series_without_results() {
|
||||
let window = RangeWindow {
|
||||
|
||||
Reference in New Issue
Block a user