mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 21:54:08 +00:00
test(promql): tell @ end() apart from the last grid point
The anchor test used a statement ending at 100s on a 5s step, so its last grid point was also 100s: binding `end()` to the last grid point instead of to the statement's own end would have passed. The end is now a parameter of the statement helper, and a statement ending at 103s pins the two apart, asserting both the anchor and that the grid still stops at 100s. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
@@ -38,10 +38,18 @@ fn raw_schema() -> Arc<SeriesSchema> {
|
||||
|
||||
/// A statement over 100 seconds in 5-second steps, which is 21 grid points.
|
||||
fn eval_stmt(query: &str) -> EvalStmt {
|
||||
eval_stmt_over(query, Duration::from_secs(100))
|
||||
}
|
||||
|
||||
/// The statement `query` over `UNIX_EPOCH..=end`, on a 5s grid.
|
||||
///
|
||||
/// The end is a parameter because a grid stops before an end it does not land on, which is the only
|
||||
/// way `end()` and the last grid point can be told apart.
|
||||
fn eval_stmt_over(query: &str, end: Duration) -> EvalStmt {
|
||||
EvalStmt {
|
||||
expr: promql_parser::parser::parse(query).unwrap(),
|
||||
start: UNIX_EPOCH,
|
||||
end: UNIX_EPOCH + Duration::from_secs(100),
|
||||
end: UNIX_EPOCH + end,
|
||||
interval: Duration::from_secs(5),
|
||||
lookback_delta: Duration::from_secs(5),
|
||||
}
|
||||
@@ -278,6 +286,36 @@ fn an_anchor_on_a_window_resolves_to_absolute_milliseconds() {
|
||||
}
|
||||
}
|
||||
|
||||
/// `end()` is the statement's end, not the last grid point.
|
||||
///
|
||||
/// The grid stops before an end it does not land on, so an end of 103s over a 5s step has its last
|
||||
/// point at 100s. Binding `end()` to that point instead of to the statement's own end would pass a
|
||||
/// test whose end is a multiple of the step; here the two numbers differ.
|
||||
#[test]
|
||||
fn end_resolves_to_the_statement_end_not_the_last_grid_point() {
|
||||
let stmt = eval_stmt_over("rate(x[5m] @ end())", Duration::from_secs(103));
|
||||
let tree = compile(&stmt, raw_schema(), SeriesOrdering::KeyThenTime).unwrap();
|
||||
let (_, op) = root_window(&tree);
|
||||
assert_eq!(
|
||||
op.window.anchor_ms,
|
||||
Some(103_000),
|
||||
"`@ end()` bound something other than the statement's end"
|
||||
);
|
||||
|
||||
// The grid the same statement compiles onto ends at 100s, so the two are not the same number.
|
||||
let spec = op.output_grid.spec();
|
||||
let last_point = spec.start_ms + (spec.len as i64 - 1) * spec.step_ms;
|
||||
assert_eq!(
|
||||
last_point, 100_000,
|
||||
"the test's own grid does not stop before the statement end"
|
||||
);
|
||||
assert_ne!(
|
||||
op.window.anchor_ms,
|
||||
Some(last_point),
|
||||
"`@ end()` bound the last grid point rather than the statement's end"
|
||||
);
|
||||
}
|
||||
|
||||
/// An anchor and an offset are bound apart: the window ends at `anchor - offset`, which the
|
||||
/// runtime folds, so both numbers have to survive compilation.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user