mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-26 12:44:10 +00:00
* feat(promql): answer the shapes the native route refused for want of a rule Three refusals in the native fused route were admissions, not missing capability. Each is answered here against main's own structure. **Grouping by `__name__` over several sources.** A tree reading more than one named source could not report the label a `by (__name__)` keeps, because only a discovered source declared it. Every metric-bound input now declares its name as a source tag when the tree reads more than one, and the two refusals that guarded this - in the planner and in `segment_tree` - are gone with `groups_by_metric_name`. **A `__field__` matcher over an input with no table.** The matcher names the only field layout such an input can declare, so it answers an empty frame of that field. An operator other than `=` stays refused: it asks what set of fields the tables carry, and there is no table to ask. **A canonical merge over a partitioned table.** `per_source_inputs` now covers `any_partitioned && contains_canonical_merge`, so the boundary's producer runs above the regions and reads a raw-series source instead of a bare scan, which is what the distributed planner already does. Two smaller rules complete the kind walk: `output_field_kind` covered Window, Instant, Map, Binary and Aggregate and fell through for the rest, so a statement rooted at a vector operation, `info` or a parameterized map named no kind at all - each answers a kind already written one arm away, and the catch-all is gone so a variant added later has to be classified. A comparison between two different kinds produces no sample (`elem_binop` skips it), so its column is the empty float layout the arithmetic arm already names. Finally, a value field is classified by what the raw series scan produces rather than by its catalog type, and admitted where the statement's shape makes the existing planner publish `Float64` for it too: arithmetic, `min`/`max`, the float-answering aggregates and the range functions whose value window is a float. A `BIGINT` table's `sum(m)` and its bare `m` stay refused - DataFusion's `sum` answers `Int64`, and a bare selector copies the column's own type, so admitting either would publish a column the existing plan publishes differently. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin a whole-vector operator standing on an aggregate The kind walk now names what a vector operation answers, so a ranking over an evaluated aggregate plans on this route - and the split declines it, which keeps the route rather than losing it: `split_aggregate` answers `None` and segmentation takes the whole statement. Both facts are load-bearing enough to pin. The plan-level test asserts a fused node and no final split for `topk`, `bottomk`, `limitk`, `limit_ratio` and `sort` over an aggregate, with a bare-scan control; the integration test compares the rows the two routes answer for the shapes both of them can run, and inspects the plan that actually executed to confirm the ranking sits above the evaluated input. Signed-off-by: discord9 <discord9@163.com> * fix(promql): an integer fold is not a float once something casts it The numeric admission asked what type the existing plan publishes for a field, and read every arithmetic operator as publishing `Float64`. That is true of the operator, not of what it wraps: `sum(v) * 1` over `BIGINT` sums the integers first and casts afterwards, so `9007199254740993` and `-9007199254740992` answer `1.0` there, while the raw scan casts each value before summing and answers `0.0`. Admitting that shape would have answered a different number. An arithmetic operator now publishes a float only when the fold under it does too. `sum(int_field) * 1`, `sum(int_field) + 1` and `count(m) + 1` keep the existing plan; `sum(rate(m[5m]))`, `m * 2` and the aggregates that answer a float of their own stay native. The series-scan preflight refused the raw path for every field of an ordinary table whenever the store was configured columnar, and nothing above could turn that refusal into a fallback, so a query `main` answered with 40 became a planning error. Only the prepared columnar reader is gated now: a table whose region needs preparation keeps the refusal, and one that merely lacks columnar coverage is served by the ordinary scan. The test that pinned the error is replaced by one that pins the answer: a columnar-configured store over ordinary `INTEGER` and `FLOAT` tables answers `sum_over_time` and `avg_over_time` from the ordinary scan, equal to the existing route. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com>