Commit Graph
5758 Commits
Author SHA1 Message Date
Dennis Zhuang bfe1bab672 chore: merge narthex into feat/narthex-select-absent-sort 2026-10-22 21:15:36 +08:00
Dennis Zhuang 6e5137f364 chore: merge narthex into feat/narthex-label-node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/promql/src/native/display.rs
#	src/promql/src/native/execute.rs
#	src/promql/src/native/execute/tests.rs
#	src/promql/src/native/plan/tests.rs
#	src/query/src/promql/native_compile.rs
#	src/query/src/promql/native_compile/tests.rs
2026-10-22 21:14:26 +08:00
dennis zhuang fbd5c8b850 feat(promql): run topk, bottomk, limitk and limit_ratio as a native select node (#9850)
I hereby agree to the terms of the [GreptimeDB
CLA](https://github.com/GreptimeTeam/.github/blob/main/CLA.md).

## Refer to a related PR or issue link (optional)

Native tree operator wiring, Select category (#25). Based on `narthex`
directly, independent of the #9845 → #9849 chain. Compiler wiring is not
here: it goes through the aggregate compile in #9833, which keeps `topk`
and friends out of `AggregateKind` as a different shape. It follows once
#9833 merges.

## What's changed and what's your intention?

`topk`, `bottomk`, `limitk` and `limit_ratio` get a node and a runtime.

- **Plan.** `NativeExpr::Select { input, op: BoundSelect }`, with
`BoundSelect::{TopK { k, top, group }, LimitK { k, group }, LimitRatio {
ratio }}`. Constants are bound, as for windows. A selection consumes and
produces the same evaluated vector.
- **Runtime.** Which samples are kept at a point depends on every series
there, so the node works like the binary node: it retains its whole
input, assembles the chunks of each logical series, runs the kernel from
`select.rs` once the input has ended, and queues the results.
- `limitk` reads series in label order. Prometheus uses label order once
a query spans head and blocks; the scan here does not order distinct
series, so this keeps the result stable across runs.
- Pieces of one label set (e.g. under a map that dropped the name) stay
pieces. They hold disjoint points, so ranking them apart picks what
ranking the merged series would, and the output keeps the input's
`holds_shared` flag.
- Multi-field `topk` / `bottomk` / `limitk` is refused when the
execution is built.
- Memory: the retained chunks and the assembly are reserved as for the
binary node, and a rough kernel workspace estimate
(`selection_workspace_bytes`, same convention as
`merge_workspace_bytes`) is reserved before the kernel runs.
- **Shared code.** `BinaryOperand` becomes `RetainedInput`. The
continuation and still-open checks move from `BinaryRuntime::retain` /
`closed` into `RetainedInput::retain` / `ensure_closed`, so both nodes
use them. Binary behavior is unchanged apart from error wording.
`compute_binary`'s queueing is factored into `queue_results`.
- **Kernel fix.** `topk` / `bottomk` skipped nothing and failed on a
histogram sample; Prometheus ignores histograms there (`aggregationK`),
and so does the kernel now.

Shared files touched: `native/plan.rs`, `native/execute.rs`
(`RetainedInput`, `NodeTag`, build/settle/pull), `native/display.rs`,
`native/metrics.rs` (`walk`).

### Tests

- Runtime: `topk` ranks a series delivered in two chunks as one
candidate and gives the reservation back; `limitk` takes label order
over arrival order, with map pieces kept where they hold the point; a
binary node above a selection reads what it kept.
- Kernel: `topk` skips a histogram sample.
- Plan: a selection over raw samples is refused. Display: the three
shapes.

## PR Checklist
Please convert it to a draft if some of the following conditions are not
met.

- [x] I have written the necessary rustdoc comments.
- [x] I have added the necessary unit tests and integration tests.
- [ ] This PR requires documentation updates.
- [x] API changes are backward compatible.
- [x] Schema or data changes are backward compatible.
- [ ] This PR needs to be backported to release branches, and I have
added the `backport-<target>` labels (e.g. `backport-v1.3` targets
`release/v1.3`).
2026-10-22 20:56:16 +08:00
dennis zhuang ca3d57cbaa feat(promql): compile and run date functions over a vector in the native tree (#9846)
I hereby agree to the terms of the [GreptimeDB
CLA](https://github.com/GreptimeTeam/.github/blob/main/CLA.md).

## Refer to a related PR or issue link (optional)

Native tree operator wiring, time/date category (the first small draft
agreed on #25). Builds on #9845 (merged), whose `map_math` skips native
histograms.

## What's changed and what's your intention?

Date functions that take a vector — `day_of_month`, `day_of_week`,
`day_of_year`, `days_in_month`, `hour`, `minute`, `month`, `year` — now
compile into the native tree and run there.

- **No new node.** Prometheus evaluates these like its math functions
(`dateWrapper` has the same shape as `simpleFloatFunc`): per float
sample, the value read as Unix seconds via `int64`, histograms skipped,
the metric name dropped. So `MathOp` gains `Date(DateFunction)`, and the
existing `Map` node, display and runtime (`map_chunk` → `map_math`)
carry it. Shared files change in a few lines: one variant and one match
arm in `map.rs`, one display arm, and the name table in the compiler.
- **Compiler.** `math_signature` lists the eight names as unary. A date
function written without an argument (`hour()`) reads the evaluation
time; it has no input to map, so it is refused as `NotImplemented`, and
the message says so. That form waits for the no-input and scalar output
interfaces.
- **One implementation.** `map_date` had no caller outside its tests, so
it is removed. The Prometheus golden for date functions now drives
`map_math(MathOp::Date(..))`, the path the runtime takes. A hole in a
float field stays a missing row on the input's axis, as with every map,
instead of cutting the axis.
- **Comments.** `map_chunk`'s comments now account for #9845: a chunk
loses the rows only histograms filled, and `None` means no float value
is left.

Output and labels: a `Map` keeps the input's fields and grid. It drops
`__name__`, `__type__` and `__unit__`, so it is one of the nodes that
can merge series into one label set, as before.

### Tests

- Prometheus golden (`map_time/prometheus_cases.txt`, existing): 100
date cases, including NaN, ±Inf and label set collisions, now through
`map_math`.
- Compiler: each date name binds its kernel, and `hour()` is refused as
`NotImplemented` naming the evaluation time.

## PR Checklist
Please convert it to a draft if some of the following conditions are not
met.

- [x] I have written the necessary rustdoc comments.
- [x] I have added the necessary unit tests and integration tests.
- [ ] This PR requires documentation updates.
- [x] API changes are backward compatible.
- [x] Schema or data changes are backward compatible.
- [ ] This PR needs to be backported to release branches, and I have
added the `backport-<target>` labels (e.g. `backport-v1.3` targets
`release/v1.3`).
2026-10-22 20:56:02 +08:00
Yingwen 6a40c0b811 feat(mito): implement columnar samples format (#9887)
* docs(mito): specify columnar samples format

Signed-off-by: evenyag <realevenyag@gmail.com>

* feat(mito): implement columnar samples format

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): address columnar samples review feedback

Signed-off-by: evenyag <realevenyag@gmail.com>

* style(mito): use crate-rooted samples imports

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-10-22 19:41:56 +08:00
Dennis Zhuang c230fb123a feat(promql): compile topk, bottomk, limitk, limit_ratio and count_values into the vector node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 19:17:15 +08:00
Dennis Zhuang 71dbde9b59 chore: merge feat/narthex-histogram-quantile-node into feat/narthex-count-values-node 2026-10-22 18:55:09 +08:00
Dennis Zhuang 3ba4476b2f chore: merge feat/narthex-select-compile into feat/narthex-histogram-quantile-node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/query/src/promql/native_compile.rs
#	src/query/src/promql/native_compile/tests.rs
2026-10-22 18:55:02 +08:00
Dennis Zhuang bd719b0859 chore: merge feat/narthex-select-absent-sort into feat/narthex-select-compile
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/query/src/promql/native_compile.rs
#	src/query/src/promql/native_compile/tests.rs
2026-10-22 18:48:11 +08:00
Dennis Zhuang f067b252da fix(promql): read the grid length from its spec now that timestamps are deferred
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 18:31:31 +08:00
Dennis Zhuang 05442cc722 chore: merge feat/narthex-select-node into feat/narthex-select-absent-sort 2026-10-22 18:27:31 +08:00
Dennis Zhuang 3419266374 feat(promql): evaluate the anchored and smoothed range modifiers
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 18:23:29 +08:00
Dennis Zhuang 4976ffa9b9 chore: merge narthex into feat/narthex-select-node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/promql/src/native/display.rs
#	src/promql/src/native/execute.rs
#	src/promql/src/native/execute/tests.rs
2026-10-22 18:06:16 +08:00
Dennis Zhuang 59a57d1ff6 chore: merge narthex into feat/narthex-date-node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/query/src/promql/native_compile.rs
2026-10-22 17:52:16 +08:00
dennis zhuang c209feda3c feat(promql): count native histograms in count_values by their Prometheus text (#9855)
I hereby agree to the terms of the [GreptimeDB
CLA](https://github.com/GreptimeTeam/.github/blob/main/CLA.md).

## Refer to a related PR or issue link (optional)

Native operator kernels (#27). Builds on the Go float formatting from
#9840 (merged). Removes the histogram caveat noted in #9854.

## What's changed and what's your intention?

Prometheus `count_values` counts a native histogram sample under the
text `FloatHistogram.String()` writes it as. The native kernel refused
histogram input with `NotImplemented`; it now counts histograms the same
way.

- `go_format::format_float_g`: Go's `%g` / `%v` for a float64 (shortest
digits, exponent below 1e-4 and from 1e6 on).
`format_open_metrics_float` now builds on it, unchanged.
- `histogram_eval::histogram_string`: Go `FloatHistogram.String`. Count
and sum come first, then the non-empty buckets from the lowest up
(negative, zero, positive), each written as `Bucket.String`. Bounds stay
as the bucket index gives them (not clipped by the zero bucket), with
the inclusiveness `baseBucketIterator.at` gives, so custom buckets print
`[-Inf,b0]` first.
- `count_values` keys a histogram by its text, so equal histograms share
a group. Series are validated with `map::validate_grid_series` (from
#9845), which accepts any sample type.

### Tests

- Golden `histogram_eval/string_cases.txt` (17 KB, 47 cases) from
`promql-compat/cmd/narthex-golden-histstring`, Prometheus v3.15.0. Fixed
cases cover the zero bucket at threshold 0 (`[-0,0]`), negative bucket
order, the exponent form, custom bounds, ±Inf and NaN, a zero-length
span, a NaN bucket count, and buckets under a wide zero threshold; 40
random cases follow. Dropping the negative-bucket reversal or the
custom-bucket inclusiveness fails it.
- `count_values` groups two equal histograms together and a float apart.

## PR Checklist
Please convert it to a draft if some of the following conditions are not
met.

- [x] I have written the necessary rustdoc comments.
- [x] I have added the necessary unit tests and integration tests.
- [ ] This PR requires documentation updates.
- [x] API changes are backward compatible.
- [x] Schema or data changes are backward compatible.
- [ ] This PR needs to be backported to release branches, and I have
added the `backport-<target>` labels (e.g. `backport-v1.3` targets
`release/v1.3`).
2026-10-22 17:40:50 +08:00
discord9 14f0ead84c feat(promql): execute constant scalar broadcasts in the native executor (#9859)
Execute compiler-emitted literal Scalar/vector arithmetic, filtering and bool comparisons, and unary negation in NativeExecutor. Reuse existing ScalarOperand and map kernels while pulling only the vector side; preserve sparse/missing values, correct labels, and series closure.

Reuse existing reservations, metrics and merge handling. Track name-dropping collisions, merge disjoint collapsed series before a downstream Window, and retain no vector stream in the broadcast. Reject unsupported computed-scalar operands at construction.

Add real compiler-to-executor and direct executor regressions for both operand directions, folded bool constants, exact 21-point results, streaming/collecting Window lifecycle, nonclosing empty filters, final closure, bounded retention and reservation release.

No duplicate compiler lowering, dynamic scalar/scalar-scalar execution, Aggregate runtime or public Fused entrypoint wiring.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-22 17:27:44 +08:00
Yingwen cff91d99bf feat(mito): implement columnar series index format (#9841)
* feat(mito): implement columnar series index format

Signed-off-by: evenyag <realevenyag@gmail.com>

* test(mito): remove columnar compatibility fixtures

Signed-off-by: evenyag <realevenyag@gmail.com>

* refactor(mito): use recorded artifact sizes and inline columnar codecs

Signed-off-by: evenyag <realevenyag@gmail.com>

* fix(mito): bound columnar series writer memory

Signed-off-by: evenyag <realevenyag@gmail.com>

---------

Signed-off-by: evenyag <realevenyag@gmail.com>
2026-10-22 17:16:18 +08:00
discord9 bf97de2ad1 feat(promql): compile subqueries with deferred grid materialization (#9835)
Compile range functions over explicit/default-step, offset, anchored, and nested subqueries using the shared range-evaluator grid calculation. Retain complete sampled coverage and reject empty child grids explicitly.

Keep compilation allocation proportional to plan structure, not timestamp count: validate deferred root and child grids; preserve eager EvalGrid::try_new; materialize shared timestamps fallibly only when a consumer requests them. Migrate Rust timestamp-buffer callers to Result without changing wire or persisted formats.

Regression coverage includes grid phase/coverage, rounded sampled endpoints, offset overflow, huge and nested compile-only grids, sparse gathering, sharing, and allocation-error propagation. Deferred compilation does not bound execution memory. No public Fused entrypoint or Scalar runtime is added here.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-22 16:48:41 +08:00
discord9 10dc8940f6 feat(promql): bind the remaining range kernels to their PromQL names (#9834)
* feat(promql): bind the remaining range kernels to their PromQL names

`RangeFunction` already names 26 functions and every one of them answers: the
kernels for `first_over_time`, `mad_over_time`, the four `ts_of_*` functions,
`predict_linear` and `double_exponential_smoothing` are all in `range_eval`. What
was missing was the compiler's name table, so these queries were refused as names
with no kernel although the kernel existed.

Six of them are the functions Prometheus marks experimental. This crate implements
them unconditionally — `RangeFunction` names them without a gate and the kernels
compute them — so binding them is the same decision as binding `rate` rather than
a new policy. If a gate is ever wanted it belongs where a query is admitted, not
scattered across the compiler's name table.

The two parameterised ones needed a second look at where the selector sits, which
is not one place in PromQL: `quantile_over_time(0.9, x[5m])` writes its quantile
before the selector, while `predict_linear(x[5m], 300)` and
`double_exponential_smoothing(x[5m], 0.5, 0.1)` write theirs after it. A single
"parameters come first" rule read the selector as a constant for the second group
and rejected an ordinary query, so the signature now states the selector's
position as data instead of relying on a convention.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 8b15ab65c0)
(cherry picked from commit d89e3064fc)

* fix(promql): preserve range argument positions in diagnostics

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

* fix(promql): bind range constants without cloning their expressions

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

---------

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-22 16:05:26 +08:00
discord9 3876831342 feat(promql): compile sum over an optionally grouped expression (#9833)
* feat(promql): bind every aggregator that folds a group's values

`AggregateKind` named only `Sum`, so the compiler bound `sum` and refused every
other aggregator by name. Six of the ones it refused fold exactly as `sum` does —
each reports one value per group per grid point — and two more (`stddev`,
`stdvar`) plus `quantile` fold the same way without a kernel yet. Binding them is
the same decision as binding `sum`: the compiler says what an aggregate means, and
the runtime refuses a kind it cannot execute. A kernel landing later then changes no
binding.

`quantile` is the one of the nine with a parameter, and it carries it in the
variant (`Quantile { quantile: f64 }`) as `RangeFunction::QuantileOverTime` does,
because `BoundAggregate` has no field a constant could go in and a field that meant
nothing for the other eight kinds would split a kind from its own parameter. That
costs `AggregateKind` `Eq`, which nothing on this tree needed: the only exhaustive
match is the display, and no collection is keyed on it.

The five that do not fold are refused with the reason rather than mapped to a kind
that would compute something else: `topk`, `bottomk`, `limitk` and `limit_ratio`
select some of the input's series, so they do not report one value per group per
grid point, and `count_values` writes one output label per distinct value.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit f1d1f3124ede003ae6df18fa0617aa13a56f3907)
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

# Conflicts:
#	src/query/src/promql/native_compile.rs
#	src/query/src/promql/native_compile/tests.rs

* test(promql): keep folded argument regressions in their compiler layer

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

---------

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-22 15:55:43 +08:00
discord9 70201c9cf9 feat(promql): compile constants, negation and scalar-vector arithmetic (#9832)
* feat(promql): compile a constant, a negation and a scalar-vector operation

Three shapes reach the tree now: a constant binds as a `Scalar` on the statement's
grid, a negation binds as the multiplication by `-1` it is, and a binary operation
between one vector and one constant binds as a `Binary` node whose output is the
vector side's own binding. The arithmetic and comparison operators all map, and
`return_bool` is carried as its own field so `x > 0` (which filters) and
`x > bool 0` (which reports zero or one) are one node with one field changed.

The operands keep the order they were written in, because most operators are not
commutative: `1 / x` is not `x / 1`, and which side the constant is on is the only
thing that tells them apart. A constant is bound by the same `constant_value` fold a
call's parameters already use, so `x * (1 + 2)` carries `3` rather than an addition
the tree would have to know how to run.

Three shapes are refused rather than approximated. An operation between two vectors
needs each `Input` to name the selector it reads, which the one binding does not
carry, so `a + b` and `a + a` would compile to the same tree; a set operator
combines two vectors' series and has no node at all; and a statement whose value is
a scalar has nothing to scan, so a constant is only bound next to a vector that
gives it something to broadcast over. Each refusal names what it found.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit e672a9c526)
(cherry picked from commit 77ea4d1f4e)

* fix(promql): refuse a modifier before folding a constant

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>

---------

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-22 15:27:21 +08:00
Dennis Zhuang c10159cf10 chore: merge narthex into feat/narthex-count-values-histograms
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/promql/src/map.rs
2026-10-22 14:48:37 +08:00
dennis zhuang 0b6ba623f0 feat(promql): partial state and merge for native float aggregates (#9826)
I hereby agree to the terms of the [GreptimeDB
CLA](https://github.com/GreptimeTeam/.github/blob/main/CLA.md).

## Refer to a related PR or issue link (optional)

Narthex operator task AGG-STATE.

## What's changed and what's your intention?

This adds partial aggregation state for native float aggregates, so an
execution partition can fold its series and a later stage can merge the
states into the result. Frame encoding, Exchange and plan wiring are not
part of it.

- `FloatAggregator::finish_partial()` returns a `PartialAggregate`. Its
groups are in first-seen order, and each group holds per grid point one
`Option<AccumulatorState>` per field; `None` means the field had no
contribution there.
- `AggregateOp::state_fields()` declares which components each
aggregation's state carries. A merge reads nothing else:
  - `sum`: value, compensation.
  - `count`: count.
- `avg`: value, mean, compensation, count, and the incremental-mean
flag.
  - `min` / `max`: value.
- `group`: nothing. Its result is 1 wherever a state exists, so `finish`
no longer reads the value.
  - `stddev` / `stdvar`: value (sum of squared deviations), mean, count.
- `FloatMerger` merges partials in any order and identifies groups by
their full label set. It rejects a partial with another aggregation,
another field count, or points outside the grid, and leaves its state
unchanged.
- Merge rules, compared with the serial fold:
- `sum`: the error of adding the two partial sums goes into the
compensation, together with both compensations.
- `avg`: sums are added while the result stays finite. Otherwise the
merge continues with the count-weighted mean, as the serial update does
once its sum overflows.
- `stddev` / `stdvar`: Chan's pairwise update, computed as `δ·(δ·w)`, so
`[0]` merged with `[1.5e154]` stays finite.
- `min` / `max`: the serial comparison. For equal `0` and `-0`, the
partial merged first wins.
- `merge_count_values` adds the counts of `count_values` partials that
share a full output label set. `quantile` has no partial and stays on
the complete path.

Regrouping changes the rounding, and it can also move an overflow of
finite values: a serial `sum` of `[1e308, 1e308, -1e308]` is `+Inf`,
while the merge of `[1e308]` and `[1e308, -1e308]` is finite. `stddev` /
`stdvar` can also differ beyond that when samples differ by about the
rounding of their mean: Prometheus' serial Welford rounds the mean per
sample, and for `[1e16] | [1e16 + 2]` it gives a variance of 2 where the
merge gives the exact 1. Explicit NaN and infinite inputs give the same
class as the serial fold. The module docs state this contract.

### Tests

- **Random partitions.** 300 seeds × 8 aggregations, plus
`count_values`: 1–3 fields of sparse input, split into random partitions
and merged in a shuffled order. Before merging, each partial is stripped
to its `state_fields`. Results must match the serial fold:
  - groups, points and fields exactly;
  - values within 1e-10;
  - bit for bit when one partition holds every series.
- **Directed cases:**
- compensation carried by a partial and created by a merge, for `sum`
and `avg`;
  - `avg` with unequal counts after one partition switched to a mean;
  - `stdvar` of `[0]` and `[1.5e154]`;
  - `min` / `max` sign of zero following merge order;
  - rejected partials.

A mean-mode compensation is at most the last bit of a mean near 1e307,
so dropping its weights is not observable within this contract and is
not pinned by a test.

## PR Checklist
Please convert it to a draft if some of the following conditions are not
met.

- [x] I have written the necessary rustdoc comments.
- [x] I have added the necessary unit tests and integration tests.
- [ ] This PR requires documentation updates.
- [x] API changes are backward compatible.
- [x] Schema or data changes are backward compatible.
- [ ] This PR needs to be backported to release branches, and I have
added the `backport-<target>` labels (e.g. `backport-v1.3` targets
`release/v1.3`).
2026-10-22 14:44:49 +08:00
dennis zhuang 99bf6a8403 feat(promql): add histogram_quantiles and share Go float formatting (#9840)
I hereby agree to the terms of the [GreptimeDB
CLA](https://github.com/GreptimeTeam/.github/blob/main/CLA.md).

## Refer to a related PR or issue link (optional)

Narthex operator task NEW-MAP-FN, remaining part.

## What's changed and what's your intention?

Adds the native kernel for the experimental `histogram_quantiles(v,
label, q...)` from Prometheus v3.15.0.

- `histogram_eval::histogram_quantiles` evaluates `histogram_quantile`
for each `q` with the existing kernel and sets `label` to `q`, formatted
as Prometheus' `labels.FormatOpenMetricsFloat` does. Results that then
share a label set merge through `merge_same_labelset`. A repeated `q`,
or a `label` that overwrites the label telling two histograms apart,
fails at a point both hold, as in Prometheus.
- The Go float formatting from #9799's `count_values` moves to a
`go_format` module, next to `go_sort`. It now offers both
`FormatFloat(v, 'f', -1, 64)` and `FormatOpenMetricsFloat`, which is
Go's shortest `'g'` format: an exponent below 1e-4 and from 1e6 on, at
least two exponent digits, `.0` appended to integers, and hardcoded
`0.0`, `1.0`, `-1.0`. Both share the round-trip-checked shortest digits.

### Tests

- `histogram_eval/quantiles_cases.txt` (37 KB, 30 cases): classic
histograms evaluated by the Prometheus engine with experimental
functions on (promql-compat `narthex-golden-histogram -quantiles`). It
includes repeated quantiles and `job` as the quantile label; 13 cases
end in the label set collision.
- `go_format/open_metrics_cases.txt` (13 KB, 358 values):
`FormatOpenMetricsFloat` outputs for the exponent switch points, the
hardcoded values, powers of two from 2^-30 to 2^30 with neighbours, and
random values (`narthex-golden-formatfloat -openmetrics`). The existing
`'f'` fixture is unchanged.

## PR Checklist
Please convert it to a draft if some of the following conditions are not
met.

- [x] I have written the necessary rustdoc comments.
- [x] I have added the necessary unit tests and integration tests.
- [ ] This PR requires documentation updates.
- [x] API changes are backward compatible.
- [x] Schema or data changes are backward compatible.
- [ ] This PR needs to be backported to release branches, and I have
added the `backport-<target>` labels (e.g. `backport-v1.3` targets
`release/v1.3`).
2026-10-22 14:44:37 +08:00
dennis zhuang 6afb0283cd feat(promql): project selected sample times for timestamp() and info() (#9836)
I hereby agree to the terms of the [GreptimeDB
CLA](https://github.com/GreptimeTeam/.github/blob/main/CLA.md).

## Refer to a related PR or issue link (optional)

Narthex operator task EVAL-TS. It also provides the input #9829's
`info()` kernel expects.

## What's changed and what's your intention?

`timestamp()` needs the original time of the sample an instant selection
chose. `select_instants` already returns the source row of each selected
point, so this adds kernels that project from that selection onto the
evaluation grid, next to `select_instants` in `instant_eval.rs`:

- `timestamp_of_selection`: `timestamp(selector)`. The value is the
original time of the selected sample in seconds. An offset or `@`
changes which sample is selected, not the time reported. Metric name,
`__type__` and `__unit__` are dropped.
- `info_sample_times`: the series `info()` reads. The value is the
original time in milliseconds, as Prometheus' `evalSeries(...,
recordOrigT=true)` records it. Labels are kept. A native histogram fails
with Prometheus' "this should be an info metric, with float samples".
- `timestamp_of_evaluated`: `timestamp()` over an evaluated expression
such as `timestamp(abs(x))`. The value is the evaluation time in seconds
where the input has a value. Metadata labels are dropped.

A field without a sample in the selected row has no value at that point.
Lookback and stale handling stay those of `select_instants`. A selection
must lie on the grid, with points and rows increasing; that lets one
cursor per field read each selected row once, even when consecutive
points select the same row.

Out of scope: wiring into the Instant runtime and the native compiler
(including `@` binding).

### Tests

`instant_eval/timestamp_cases.txt` (22 KB) comes from the Prometheus
engine via promql-compat `narthex-golden-timestamp`. Samples sit at
arbitrary milliseconds, so original and evaluation times differ. It has
40 random cases plus fixed ones for:
- a sample exactly one lookback before a point (excluded);
- a stale marker;
- an offset, over a selector and over an evaluated expression.

Unit tests cover:
- the millisecond output, labels and missing fields of
`info_sample_times`;
- histogram samples (rejected for `info`, accepted for `timestamp`);
- rejection of selections off the grid or going back.

## PR Checklist
Please convert it to a draft if some of the following conditions are not
met.

- [x] I have written the necessary rustdoc comments.
- [x] I have added the necessary unit tests and integration tests.
- [ ] This PR requires documentation updates.
- [x] API changes are backward compatible.
- [x] Schema or data changes are backward compatible.
- [ ] This PR needs to be backported to release branches, and I have
added the `backport-<target>` labels (e.g. `backport-v1.3` targets
`release/v1.3`).
2026-10-22 14:44:25 +08:00
Dennis Zhuang c63902509e fix(promql): estimate count_values groups per field sample
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 14:19:35 +08:00
Dennis Zhuang cf09641d04 chore: merge feat/narthex-histogram-quantile-node into feat/narthex-count-values-node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/promql/src/native/execute.rs
2026-10-22 14:18:20 +08:00
Dennis Zhuang 0279e12889 chore: merge feat/narthex-select-compile into feat/narthex-histogram-quantile-node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/promql/src/native/display.rs
#	src/promql/src/native/execute.rs
#	src/promql/src/native/execute/tests.rs
#	src/query/src/promql/native_compile.rs
#	src/query/src/promql/native_compile/tests.rs
2026-10-22 14:11:45 +08:00
Dennis Zhuang abb55be608 refactor(promql): follow the Vector rename in the compiler
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 14:05:38 +08:00
Dennis Zhuang bf3ae6ab60 chore: merge feat/narthex-select-absent-sort into feat/narthex-select-compile 2026-10-22 14:01:35 +08:00
Dennis Zhuang b7dfb8ec3d fix(promql): keep a shared histogram table charged until the last queued result leaves
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 14:00:38 +08:00
Dennis Zhuang 5dbda4d9cd chore: merge feat/narthex-select-node into feat/narthex-select-absent-sort
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

# Conflicts:
#	src/promql/src/native/display.rs
#	src/promql/src/native/execute.rs
2026-10-22 13:54:00 +08:00
Dennis Zhuang 90478ec493 refactor(promql): name the whole-vector node Vector
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 13:46:11 +08:00
Dennis Zhuang bec5f76637 fix(promql): keep the input order for limitk and merge label-set pieces instead of sorting
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 13:39:12 +08:00
Dennis Zhuang bc782ac5da feat(promql): count native histograms in count_values by their Prometheus text
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 06:14:09 +08:00
Dennis Zhuang e6ed74ebd1 feat(promql): run count_values in the native select node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 05:50:02 +08:00
Dennis Zhuang 7e0325780e chore(promql): return the group slot directly
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 05:40:15 +08:00
Dennis Zhuang 8bc2c8aa55 feat(promql): run histogram_quantile and histogram_fraction in the native select node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 05:39:09 +08:00
Dennis Zhuang 3d19a1f3fc feat(promql): compile sort and absent into the native select node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 05:21:13 +08:00
Dennis Zhuang 353149cf63 feat(promql): run sort and absent in the native select node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 05:05:48 +08:00
Dennis Zhuang 63a7d814a0 feat(promql): run topk, bottomk, limitk and limit_ratio as a native select node
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 04:49:02 +08:00
Dennis Zhuang cc62f32b4a feat(promql): compile and run native histogram functions as map operations
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 04:04:31 +08:00
Dennis Zhuang 0efeae0f1d feat(promql): compile and run label_replace and label_join as map operations
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 03:47:42 +08:00
Dennis Zhuang 7217bf43fb refactor(promql): run date functions only through map_math and refine the review points
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 03:14:53 +08:00
Dennis Zhuang e06f5b3f58 feat(promql): compile and run date functions over a vector in the native tree
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 03:01:48 +08:00
Dennis Zhuang d79a5f6bfe test(promql): keep Go float format tests with go_format and pin histogram_quantiles constants
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 02:38:52 +08:00
Dennis Zhuang 607719dc9d fix(promql): validate instant selections in one pass and format info errors like Prometheus
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 02:37:27 +08:00
Dennis Zhuang e61a6f42eb chore: merge narthex into feat/narthex-eval-ts
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 02:32:18 +08:00
Dennis Zhuang 7c139a2ccc feat(promql): skip native histogram samples in math functions and cover review gaps
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 02:31:40 +08:00
Dennis Zhuang e4d1b79b76 feat(promql): evaluate round and clamp with time-varying scalar parameters
Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-22 02:12:48 +08:00