Commit Graph
6775 Commits
Author SHA1 Message Date
discord9 06b28e08d8 refactor(promql): bind fused inputs by execution source index
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-24 20:01:43 +08:00
discord9 9eaa14878b test(sql): record fused multi-selector semantic regression
Twenty rows over four series cover the two-occurrence forms the fused
planner admits (default addition, order-sensitive subtraction, an
explicit full-key join and a bool comparison) plus the shapes that must
stay on the legacy path: different matchers, group_right, an anchored
rate with offset, an aggregation and a subquery. The result file is
generated by the pinned sqlness runner; a second run reproduced it byte
for byte. This case proves SQL semantics only: the per-query native hint
is not sent by this runner, so native routing and multi-partition
execution are verified separately over HTTP.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 73faca0ecb)
2026-10-24 19:03:59 +08:00
discord9 8d9b746053 fix(promql): bind fused inputs only after full identity admission
Reuse the shared cross-series reads and pointwise/full-key proofs instead of
a temporary root Binary allowance: a single occurrence may broadcast or
negate, and two occurrences share one actual source only when the root is
one-to-one, both operands are pointwise, and the complete keys prove the
same series. Aggregates and vector nodes under a Binary, Map or scalar
now fall back. Also require the exact physical input arity before the
adapter indexes bindings, so a mismatched call returns a Plan error
instead of panicking.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 988ac3616b)
2026-10-24 19:03:59 +08:00
discord9 39e2139b53 fix(promql): keep shared selector inputs partition local
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit c1385d198f)
2026-10-24 19:03:59 +08:00
discord9 027b1c49a8 fix(promql): preserve child notifications while polling fused inputs
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit e9b7e6b753)
2026-10-24 19:03:59 +08:00
discord9 0b4fc1c6a0 fix(promql): preserve fallback context and selector anchor bounds
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-24 19:03:59 +08:00
discord9 b7ad637f1f feat(promql): run a native tree over one independent scan per selector
A PromQL vector–vector binary operation now runs on the native fused-series path. Each selector of
the statement is bound to its own scan, and the compiled tree reads them as separate inputs:

- `compile_selectors` answers one `CompiledInput` per selector — where the executor reads it
  (`NodePath`), what the selector asked a scan for (`SelectorRequirement`: metric, matchers, offset,
  `@` anchor, the grid it is evaluated on, and whether it reads an instant or a window, from which
  `raw_scan_bounds()` derives the raw scan interval), the layout it was bound to and the ordering the
  scan guarantees.
- The planner prepares one `TableScan` per selector from that selector's own context — its metric,
  its own matchers as row filters, its own fields and tags — then adds the time filter from the
  requirement the compiler produced for that selector. A window and an instant differ in which edge
  they start from, and an `@` anchor moves the whole interval, so deriving the interval from the
  statement's endpoints would scan the wrong range.
- `FusedSeries` carries one `FusedSeriesInput` per selector, and `FusedSeriesExec` decodes each
  child against that input's own schema, materialises its labels, and pushes its chunks at that
  input's `NodePath`. The tree settles once, when every input has ended.
- Vector arithmetic and comparisons compile with `on` / `ignoring`, `group_left` / `group_right` and
  the `fill`, `fill_left`, `fill_right` values, and `bool` comparisons.

Scan parallelism is kept: every input is prepared with `execution.target_partitions` ranges, so one
region still scans as several partitions.

One input keeps the old behaviour — one tree execution per scan partition — because the series
producer keeps a whole series in one partition.

Several inputs do **not** run per partition. Two independent scans balance their ranges by row count,
so the same series can land in partition 0 of one and partition 1 of the other; matching per
partition index would then silently drop that match. Until there is an exchange that pairs the
matching series of each input, a node with several inputs runs as **one** execution that reads every
partition of every input (`gather_partitions`). It reports `UnknownPartitioning(1)` so nothing
downstream assumes the children's layout, and each child is executed when the gathered stream reaches
it, so the plan below stays a plan until it is read.

The tree evaluation of a multi-input query is therefore serial across scan partitions. The scan
itself is not: each partition still builds its range streams concurrently, and a partition's ranges
are still read in parallel.

- Output columns are classified against the **tree's** root schema, not the first input's: `a=[x,y] +
  b=[z]` reports `x`, and reading that off the input would accept an output schema naming a field no
  input produced.
- A `__field__` matcher makes the route decline (`Ok(None)` → legacy planner). The raw series scan
  reports every field it carries, so binding all of them would fold fields the query excluded.
  Accepting the matcher and ignoring it silently scanned the wrong field set.
- The split-logical-series guard now checks **ancestry** rather than walk order: a window is only
  endangered by a rewriter below it, and `rate(a[5m]) + rate(b[5m])` — two sibling windows — is two
  subtrees, not an ancestor pair.
- `POLL_BUDGET` is charged per child poll, so a node with several inputs cannot multiply the work one
  poll does by its child count.
- The planner and the compiler now agree on which selector is which: `collect_selectors` walks
  `Binary` operands left-then-right (it did not walk them at all before, so a binary query silently
  fell back to the legacy planner), and the binding callback checks each requirement against the
  selector at the same position before accepting it. The walk now also descends unary, aggregate and
  subquery nodes, which the compiler recurses into.
- `EnforceDistRequirementRewriter` stops at a fused node's branch instead of refusing every node with
  more than one input. Its column requirements are scoped by a level of one child chain, and the only
  projections it amends sit above the branch; each child here is a region scan, which has none.
- `TQL EXPLAIN` and `TQL EXPLAIN VERBOSE` offer their body to the native compiler and wrap the plan it
  makes, so an explanation shows the plan that query actually runs. `ANALYZE` is left to the existing
  path.

`cargo nextest run -p promql`: 838 passed, 0 skipped.
`cargo nextest run -p query`: 981 passed, 2 skipped (one earlier run hit a deferred-grid test that
materialises a `usize::MAX`-sized axis; it passes in the suite and on its own).
`cargo nextest run -p query --test native_multi_selector`: 10 passed — real compiler → real executor,
covering `on`, `ignoring`, `group_left`, `group_right`, fills, comparisons, nested trees, repeated
metrics with different windows, per-selector time ranges, and two scans that place the same series in
opposite partitions.

Standalone `/v1/promql` with `[query] experimental_native_promql = true` and `parallelism = 4`, on a
table whose four series sit in three flushed ranges (so one region holds several scan ranges), all
nine queries compared against the legacy planner row by row (labels, values, timestamps):

| query | native plan | same as legacy |
| --- | --- | --- |
| `bf{kind="a"} + on(host) bf{kind="b"}` | `Binary + on [host] one-to-one`, 2 scans × 4 partitions | 2 series × 6 points |
| `bf{kind="a"} / ignoring(kind) bf{kind="b"}` | `Binary / ignoring [kind] one-to-one`, 2 × 4 | 2 × 6 |
| `bf{kind="a"} + on(host) group_left(kind) bf{kind="b"}` | `Binary + on [host] many-to-one [kind]`, 2 × 4 | 2 × 6, labels `{host, kind="b"}` |
| `bf{kind="a"} > bool on(host) bf{kind="b"}` | `Binary > bool on [host] one-to-one`, 2 × 4 | 2 × 6 |
| `rate(bf{kind="a"}[3s]) + on(host) rate(bf{kind="b"}[3s])` | `Binary + on [host]` over two `Window rate [3000ms]`, 2 × 4 | 2 × 6 |
| `bf{host="h1",kind="a"} + on(host) bf{host="h2",kind="b"}` | 2 × 4 | empty in both |
| `bf2 + bf2` (two fields) | `Binary + ignoring []`, 2 × 4, `fields=2` | 2 × 6 |
| `rate(bf2[3s]) + rate(bf2[3s])` | two windows, 2 × 4, `fields=2` | 2 × 6 |
| `bf2{__field__="v1"} + bf2` | no native node — declined for the `__field__` matcher | 2 × 6 |

Evidence the native plan ran, from the physical planner's own debug log (an `EXPLAIN` stops at the
logical plan; this is the plan the region built):

```
FusedSeriesExec: bf{kind="a"} + on (host) bf{kind="b"}
NativeTree
  root Binary + on [host] one-to-one
    left Instant lookback 300000ms offset 0 on grid 1700000001000/1000x6
      input Input raw samples
    right Instant lookback 300000ms offset 0 on grid 1700000001000/1000x6
      input Input raw samples
  SeriesScanExec: source=primary_key, fields=1, partitions=4
  SeriesScanExec: source=primary_key, fields=1, partitions=4
```

Both scans keep four partitions, which is the configured `parallelism`: the node's output is one
partition, but the scanning is not serialised into one.

- An exchange that pairs the matching series of two inputs, which would let a multi-input tree run one
  execution per partition again.
- `info()`'s second input, scalar–vector operations, set operators, subquery execution and the
  distributed path.

Signed-off-by: discord9 <discord9@163.com>
2026-10-24 19:03:59 +08:00
discord9 9a01dd9780 test(promql): distinguish binary input fields and shared prefixes
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-24 18:58:16 +08:00
discord9 762169b97d fix(promql): run one-to-many fill on the side the query wrote
prometheus/prometheus#19939 made fill_left and fill_right name the side
written in the query rather than the matching's one and many sides, and
the kernel now swaps them with the operands under group_right. The
compiler's refusal of that combination is therefore stale, and it turned
a query the kernel answers correctly into a fallback. Drop it, and cover
the semantics with two different fill values so a swap stays visible:
group_right fill_left(5) fill_right(7) answers a right series with no
left counterpart as 5 - 4 and a left series with no right counterpart as
2 - 7.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 9a0b8680d7)
2026-10-24 18:58:16 +08:00
discord9 8086c382a1 fix(promql): retain structural paths when compiling vector operands
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 519d424bba)
(cherry picked from commit d769038b82)
2026-10-24 18:58:16 +08:00
discord9 e20b1f80d7 fix(promql): decline unsupported group-right fills
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit fdcb00e166)
2026-10-24 18:58:16 +08:00
discord9 1c87c53663 feat(promql): compile vector binary expressions with independent inputs
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit f1da64fadc)
2026-10-24 18:58:16 +08:00
discord9 70023874d5 fix(promql): verify selector paths against compiled inputs
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
2026-10-24 18:56:50 +08:00
discord9 b3dcf28d8a test(promql): verify structural selector bindings and subquery bounds
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
(cherry picked from commit 936a0eca81)
(cherry picked from commit a31d2f8f88)
2026-10-23 20:28:38 +08:00
discord9 373f84bab9 feat(promql): expose selector scan requirements and input bindings
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit ee992adb28)
2026-10-23 20:28:38 +08:00
discord9 990d932198 fix(query): keep label rewrites on the existing plan
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 20:06:13 +08:00
discord9 c6881447c1 fix(promql): bind native input to common scan ordering
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:39 +08:00
discord9 afca3328f6 test(sql): record generated TQL view regression results
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit 93fc2db0e4ee3eb46507865c8869d9426ac7ea2f)
2026-10-23 19:57:39 +08:00
discord9 bb5a7ee540 test(promql): clarify partition fixture and allow richer explain
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit ee5566d201774983e235716a67f2600b267c7c99)
2026-10-23 19:57:39 +08:00
discord9 ada66665f3 test(sql): cover textual TQL view definitions
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit 9df296e65b7e1c45b64c1e48906afa0f02013bce)
2026-10-23 19:57:39 +08:00
discord9 ea060286cc test(promql): require real partition output and strict native results
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit a13b1a723e7839f5b4e799a4493a507369de8893)
2026-10-23 19:57:39 +08:00
discord9 980edef08d test(promql): observe actual fused region execution
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit 313c8c181f3331bbaa67539a2739e26d6d0e3dec)
2026-10-23 19:57:39 +08:00
discord9 c1dcac0f2b test(promql): verify actual frontend results and view definition
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit 64a52a2a87245f16c4f2c7be20ba275302e586df)
2026-10-23 19:57:39 +08:00
discord9 c48c5ec5e1 test(promql): execute native standalone queries and compare results
Signed-off-by: discord9 <discord9@163.com>
(cherry picked from commit 12ea89c6ca329a91b6b3ee50ff73c93ab6626dc1)
2026-10-23 19:57:39 +08:00
discord9 d62051e12a fix(query): preserve logical metric field order in native scans
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:39 +08:00
discord9 cd64176418 fix(sql): preserve lookback when displaying TQL view definitions
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:39 +08:00
discord9 27cd09ec55 fix(query): keep TQL views serializable and expose native diagnostics
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:39 +08:00
discord9 340ea2d71e fix(query): retain metric table restriction in native scans
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 29ef60f6e8 test(promql): restore scan assignment coverage and update native guide
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 51da078dc8 chore(query): clear the two lints clippy reports on this branch
A doc comment on the categorizer was followed by a blank line, and the test
table builder takes eight arguments. Both are what CI's `-D warnings` turns
into errors; neither changes behaviour.

Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 ca804689eb chore(query): share the offset conversion and correct a column-order note
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 8e55a48952 refactor(promql): keep one cross-series predicate for both callers
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 ff1288f178 fix(query): match the raw scan's own field and engine rules
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 de97d86800 fix(query): only offer the native route to an engine that serves frames
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 638d485024 fix(query): decline the native route where it cannot reach a region
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 1ced0f7fdb chore(query): share the range assignment with every caller
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 8efec61743 fix(promql): keep the fused scan's parallelism
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 5527c751d2 fix(query): decline the native route where no raw scan exists
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 129faa4e49 chore(query): drop a needless borrow on the scan schema
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 0d29dc98e8 fix(query): emit the fused output in the existing column order
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 67a3d22c5b fix(query): keep a fused route to series a region owns
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 64f039eaf4 test(query): run the encoding checks for both transports
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 6121600789 fix(query): keep ordinary plans on the encoding path
Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 da27d115ca feat(query): let a region input travel as a plan when regions are in process
A plan holding a node with no Substrait serializer was always cut at that node,
because the analyzer asks whether a plan encodes before it asks whether a node
commutes with the region split. That is right for a region reached over the wire:
the plan is encoded into the request and has to decode on the other side.

Standalone does not use that path. Its region server is the one built in the same
process, its query handler passes the request straight to `RegionServer::handle_read`,
and the plan stays a `LogicalPlan` from the frontend to the region. Encoding it is
work nobody reads, and refusing to place a node because it cannot be encoded
refuses a plan that would have travelled intact.

So the engine now knows whether its regions are reached in process, and the
encodability gate applies only when they are not. The capability is set where it
can be stated truthfully - the standalone bootstrap, which creates both the
frontend and the region server it reads - and it defaults to false everywhere
else, so an ordinary build and every other deployment keeps today's behaviour
byte for byte.

Skipping the gate skips one early return and adds no reason to expand:
`Categorizer::check_plan` still runs and still decides, and a plan that does not
encode for any other reason still expands at the node that caused it. Two tests
hold those two halves apart.

Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 ba9f36fdd0 docs(query): say what the fused placement does not prove
The arm above answers that a fused node commutes with the region split, and it
listed "no series is split across regions" among its reasons. That is not
established anywhere. A region evaluates the whole tree over the series its own
scan returns, so a series whose samples reach two regions is evaluated per
fragment, and a range function over a fragment is not the range function over the
series.

What the placement does have is three proofs about the node - its input is the
scan, it binds a metric name, and no node of its tree folds across series. What it
does not have is any check that the series stays in one region: the storage
partition key is whatever `partition_column_names()` names and may be a column
that varies within one series, and this categorizer runs before region selection,
so there is no selected-region vector here to consult either.

So the comment now says that plainly, names the deployment the placement is
correct under, and says what would make it unconditional. A single-region
deployment satisfies it; a partitioned table over several regions would answer
wrongly rather than fail.

Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 ff6c5db307 feat(query): place a fused node region-side, and ask for per-series scans
A `FusedSeries` node is built for one metric's series, and a region holds a subset
of those series with none split across regions, so the node commutes with the
region split when what it reads is per-series. It says so now, and the analyzer
may place it inside the merge scan.

Three conditions, each drawn from the conversion that has to succeed there:

- The node's input is exactly the table scan. The region builds the node from the
  scan's own raw-series entrypoint and cannot look through a filter, a projection
  or a sort in between, so a node over anything else has nothing to read where it
  would be placed.
- The node binds a metric name, because the region resolves the series of one
  named metric.
- No node of its tree folds across series. A region holds part of a metric's
  series, so an aggregate or a binary operation evaluated there would consume a
  partial input and return a wrong answer without saying so. Every operation the
  compiler emits today - input, instant, window, map - reads one series at a
  time, so this refuses nothing buildable; it is the conservative answer for a
  tree built some other way.

A scan below such a node also asks for the per-series distribution now. That is
what makes a region prepare its series scan, and only that path packs a series'
chunks into the frame the node reads.

Both are inert without a `FusedSeries` node, so an ordinary query keeps its plan
and its scan request.

Not yet reached: the analyzer asks whether a plan encodes before it asks whether
a node commutes, and this node has no Substrait serializer, so the plan is
expanded at the node and the region still receives the bare scan. A test pins
that boundary so it fails the day the node can cross it.

Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
discord9 4beb5c7490 feat(query): offer a PromQL statement to the native fused-series route
Nothing called `native_compile::compile` or built a `FusedSeries`, so the native
tree and its node were library code with tests and no query behind them. This
adds the route, behind a per-query flag.

The statement is offered to the compiler at the root, where the expression the
reader wrote still exists. A shape the compiler refuses - `NotImplemented` - is
this route declining the query, and planning continues exactly as it would with
the flag off. Anything else is a real error.

The physical half is an arm in `PromExtensionPlanner`. Its children are already
built by then, so a metric scan arrives as the region scan, and the node asks that
scan for its named raw-series binding: `try_to_named_series_scan` resolves the
label source and ordering from the scanner itself, which is the only thing that
can name them, and returns the leaf the node reads. A scanner that cannot serve a
raw frame is reported, not silently re-planned.

Two things this needed that the route does not get for free:

- The region scan has to be prepared as one partition. `resolve_named_series_binding`
  refuses a scan whose partition count is not one, and a fresh scan has not set
  its partitions at all: `ParallelizeScan` runs after extension planning and would
  spread it, so the node would run one evaluator per partition and split a logical
  series. Preparing the ranges as one partition is what keeps `FusedSeriesExec`
  over one series stream, and it is why this route does not scan in parallel yet.
- The scan needs the per-series distribution hint. That is what makes a region
  prepare its series scan, and only that path packs a series' chunks into the frame
  this node reads. The existing planner asks for it through a sort that
  `ScanHintRule` turns into the hint; this node has no such sort below it, so the
  hint is attached to the scan directly.

A query the route cannot bind faithfully keeps the existing plan rather than a
wrong one: more than one selector, a label matcher that would survive
preprocessing, an `__field__` matcher, a native histogram field, a missing table,
or a shape whose grid the compiler's statement cannot express.

Signed-off-by: discord9 <discord9@163.com>
2026-10-23 19:57:38 +08:00
dennis zhuang 8497382673 feat(promql): compile and run label_replace and label_join as map operations (#9848)
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, label category (#25). Builds on #9846 (date
wiring, merged).

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

`label_replace` and `label_join` now compile into the native tree and
run in the existing `Map` node.

- **Plan.** `BoundMap.ops` becomes `Arc<[MapOp]>`, with
`MapOp::Math(MathOp)` and `MapOp::Label(Arc<LabelRewrite>)`. A label
change is pointwise per series like math, so it needs no new node,
collector or output type.
- **Kernel.** `LabelRewrite` (in `map_label.rs`) is the checked,
compiled change: `replace` anchors the regex and checks the destination,
`join` checks source and destination names, `apply` rewrites one
`MetricName`. The whole-vector `label_replace` / `label_join` now go
through it and still merge same-labelset series afterwards, so the
Prometheus golden keeps covering the same code. Fields are private, so
only the two constructors build one.
- **Runtime.** `map_chunk` applies label ops to the series metric and
math ops through `map_math`. When a math op empties a closing chunk, the
labels of the closing series come from applying the remaining ops in
order (label ops rewrite, math ops drop the name). Series a label change
folds into one label set go through the `Emitted` ledger the map already
keeps: disjoint values merge, a shared point is refused.
- **Compiler.** `label_rewrite` reads the string-literal arguments.
Arguments Prometheus rejects at evaluation (invalid regex, empty label
name) fail the statement with `Plan`, as Prometheus fails the query;
everything unsupported stays `NotImplemented`.
- **Display.** `label_replace "dst" "repl" "src" "regex"` / `label_join
"dst" "sep" ["a", "b"]`.

Shared files touched: `native/plan.rs` (`MapOp`), `native/execute.rs`
(`map_chunk`, `no_row_series` now takes the metric),
`native/display.rs`, `native_compile.rs`. Test constructors move from
`MathOp` to `MapOp::Math`.

Known difference, not introduced here but now reachable: Prometheus
checks same-labelset duplicates separately for floats and histograms,
while the native ledger counts both as a value at a position. A
`label_replace` that folds a float series and a histogram series onto
one label set at the same step is refused natively.

### Tests

- Runtime: a relabel that folds two series refuses the shared point; a
closing chunk emptied mid-chain carries labels from label ops on both
sides of the emptying op; a label-only map hands histogram samples and
holes through unchanged.
- Compiler: both functions bind their change into a map; an invalid
regex fails the statement with `Plan`.
- `map_label` Prometheus golden (existing) now runs through
`LabelRewrite`.

## 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-23 18:07:51 +08:00
dennis zhuang 3674b33db8 fix(promql): keep fill_left and fill_right on their written sides under group_right (#9899)
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)

prometheus/prometheus#19939

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

The native binary kernel applied `fill_left` / `fill_right` after
swapping the operands of `group_right`, so under `group_right`
`fill_left` filled a missing right-hand sample and `fill_right` a
missing left-hand one. That is the Prometheus behavior before
prometheus/prometheus#19939, which was merged into Prometheus main on
2026-10-13: the fill values now swap together with the operands, so they
always refer to the side written in the query.

For example, `node_meta - on(instance) group_right fill_left(5)
fill_right(7) cpu_info`: a missing `node_meta` must give `5 - cpu_info`
and a missing `cpu_info` must give `node_meta - 7`.

- `binary_field` swaps `fill.lhs` / `fill.rhs` when the one side is the
left, matching `VectorBinop` after #19939. The `FillValues` doc now
states the as-written meaning.
- `fill_cases.txt` is regenerated by promql-compat
`narthex-golden-vector -experimental fill` built against Prometheus at
the #19939 merge commit (same seed and case count). Only the 24
`group_right` cases whose fill fires on an asymmetric pair change.

No released Prometheus contains #19939 yet (v3.15.1 still has the old
behavior), so until the next release native results differ from released
Prometheus for asymmetric fills under `group_right`. The compiler does
not bind vector-vector fill modifiers yet, so this is not reachable from
a query today; it has to land before that wiring does.

## 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-23 16:44:07 +08:00
dennis zhuang 1c63b06265 feat(promql): compile topk, bottomk, limitk, limit_ratio and count_values into the vector node (#9890)
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 / aggregate categories (#25).
Follows #9850 → #9851 → #9852 → #9853 → #9854 (all merged) and #9833.

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

`topk`, `bottomk`, `limitk`, `limit_ratio` and `count_values` now
compile. #9833 left them out of `AggregateKind` because they do not fold
a group into one value per point. They now bind as a `Vector` node
through `vector_aggregate`:

- `topk` / `bottomk` / `limitk`: `k` is folded to a constant as
`quantile`'s parameter is, and the `by` / `without` grouping is kept. A
`k` only known at run time is refused with `NotImplemented`. NaN,
negative and out-of-range `k` are left to the kernel, which fails or
answers at evaluation as Prometheus does.
- `limit_ratio`: the ratio is folded the same way. The grouping is
dropped, since Prometheus keeps or drops each series by its label hash
alone.
- `count_values`: the label is a string literal. Label validation stays
in the kernel, an execution error as in Prometheus.

The module doc, the grammar and the `SUPPORTED` text name the new
shapes.

### Tests

- Compiler: each aggregator binds its operation with the folded
parameter and grouping. A run-time `k` is refused, and the rejection
quotes every aggregator this compiler takes.

## 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-23 16:21:20 +08:00