mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 13:44:03 +00:00
docs(promql): write down what an anchored window reads, and cover a pre-epoch anchor
An `@`-anchored window reads `(anchor - offset - range, anchor - offset]`, which can lie entirely outside the statement's own range, so whoever binds the scan has to derive it from the window rather than from `stmt.start` and `stmt.end`. A scan bound to the statement alone leaves such a window with no samples, and the query returns empty without an error. That contract was nowhere in the code. The anchor cases only covered non-negative anchors, so a helper that defaulted a pre-epoch anchor to zero would have kept the suite green. `rate(x[5m] @ -1.5)` now pins -1500, which is the `Err(earlier)` branch of the conversion. The `assert_ne!` at the end of the `end()` test was implied by the two equalities above it and could not fail on its own. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
@@ -270,6 +270,13 @@ fn lookback_millis(lookback: u128) -> Result<i64> {
|
||||
/// range they name, so they are resolved against `stmt.start` and `stmt.end` here. The offset is not
|
||||
/// folded in: [`RangeWindow`] keeps anchor and offset apart and ends the window at
|
||||
/// `anchor_ms - offset_ms` at run time.
|
||||
///
|
||||
/// An anchor decouples the window's read range from the statement's: it reads
|
||||
/// `(anchor_ms - offset_ms - range_ms, anchor_ms - offset_ms]`, which for an anchor like `@ 1234` can
|
||||
/// lie entirely outside `[stmt.start - range_ms, stmt.end]`. Whoever binds the scan therefore has to
|
||||
/// derive its range from the window's anchor, offset and range rather than from `stmt.start` and
|
||||
/// `stmt.end`; a scan bound to the statement alone leaves such a window with no samples, and the
|
||||
/// query silently returns empty instead of failing.
|
||||
fn selector_anchor_ms(at: &Option<AtModifier>, stmt: &EvalStmt) -> Result<Option<i64>> {
|
||||
match at {
|
||||
None => Ok(None),
|
||||
|
||||
@@ -269,6 +269,9 @@ fn an_anchor_on_a_window_resolves_to_absolute_milliseconds() {
|
||||
("rate(x[5m] @ 1234)", 1_234_000),
|
||||
// A sub-second anchor resolves to the millisecond it names.
|
||||
("rate(x[5m] @ 1.234)", 1_234),
|
||||
// Prometheus allows a pre-epoch anchor: `signed_millis_since_epoch` takes `Err(earlier)`,
|
||||
// where a `duration_since(UNIX_EPOCH).unwrap_or_default()` helper would silently give 0.
|
||||
("rate(x[5m] @ -1.5)", -1_500),
|
||||
// The statement here is UNIX_EPOCH..100s, which is what `start()` and `end()` mean.
|
||||
("rate(x[5m] @ start())", 0),
|
||||
("rate(x[5m] @ end())", 100_000),
|
||||
@@ -309,11 +312,6 @@ fn end_resolves_to_the_statement_end_not_the_last_grid_point() {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user