mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-15 00:12:29 +00:00
* fix(promql): return range-vector results for instant queries An instant query of a range selector or subquery (e.g. `up[5m]`) returned the internal range arrays, which panicked when the frontend decoded them as dictionaries. Plan such queries as the selected samples with their own timestamps, and reject range-vector expressions in range queries like Prometheus does. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): keep encode_substrait on a valid range query A range query of a range-vector expression now fails like in Prometheus. Wrap the subquery in max_over_time so the case still encodes both RangeManipulate nodes through substrait. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): plan wrapped range-vector roots and reject a zero subquery step TQL EXPLAIN, ANALYZE and AS alias wrap the root in an extension, which the range-vector path did not unwrap. A zero subquery step divided by zero. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): cover wrapped range-vector roots and a zero subquery step Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): default subquery step and reject range vectors in range queries A root subquery without a step uses the one-minute default instead of the query step. The HTTP range query endpoint rejects range-vector expressions even when start equals end. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test: cover root subquery default step Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): align root subqueries with subquery_child_window Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): return millisecond timestamps for range-vector results Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): keep the time index timezone and name its table in errors Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
56 lines
6.0 KiB
Plaintext
56 lines
6.0 KiB
Plaintext
create table count_total (
|
|
ts timestamp time index,
|
|
tag_a string,
|
|
tag_b string,
|
|
val double,
|
|
primary key (tag_a, tag_b),
|
|
);
|
|
|
|
Affected Rows: 0
|
|
|
|
-- if `RangeManipulate` can be encoded/decoded correctly in substrait, the following queries should pass
|
|
-- SQLNESS REPLACE (peers.*) REDACTED
|
|
-- SQLNESS REPLACE (partitioning.*) REDACTED
|
|
tql explain (0, 100, '1s')
|
|
max_over_time(increase(count_total{
|
|
tag_a="ffa",
|
|
}[1h])[12h:1h]);
|
|
|
|
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| plan_type | plan |
|
|
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| logical_plan | MergeScan [is_placeholder=false, remote_input=[ |
|
|
| | Filter: prom_max_over_time(ts_range,prom_increase(ts_range,val,ts,Int64(3600000))) IS NOT NULL |
|
|
| | Projection: count_total.ts, prom_max_over_time(ts_range, prom_increase(ts_range,val,ts,Int64(3600000))) AS prom_max_over_time(ts_range,prom_increase(ts_range,val,ts,Int64(3600000))), count_total.tag_a, count_total.tag_b |
|
|
| | PromRangeManipulate: req range=[0..100000], interval=[1000], eval range=[43200000], time index=[ts], values=["prom_increase(ts_range,val,ts,Int64(3600000))"] |
|
|
| | PromSeriesDivide: tags=["tag_a", "tag_b"] |
|
|
| | Sort: count_total.tag_a ASC NULLS FIRST, count_total.tag_b ASC NULLS FIRST, count_total.ts ASC NULLS FIRST |
|
|
| | Filter: prom_increase(ts_range,val,ts,Int64(3600000)) IS NOT NULL |
|
|
| | Projection: count_total.ts, prom_increase(ts_range, val, count_total.ts, Int64(3600000)) AS prom_increase(ts_range,val,ts,Int64(3600000)), count_total.tag_a, count_total.tag_b |
|
|
| | PromRangeManipulate: req range=[-39600000..100000], interval=[3600000], eval range=[3600000], time index=[ts], values=["val"] |
|
|
| | PromSeriesNormalize: offset=[0], time index=[ts], filter NaN: [true] |
|
|
| | PromSeriesDivide: tags=["tag_a", "tag_b"] |
|
|
| | Sort: count_total.tag_a ASC NULLS FIRST, count_total.tag_b ASC NULLS FIRST, count_total.ts ASC NULLS FIRST |
|
|
| | Filter: count_total.tag_a = Utf8("ffa") AND count_total.ts >= TimestampMillisecond(-43199999, None) AND count_total.ts <= TimestampMillisecond(100000, None) |
|
|
| | TableScan: count_total, partial_filters=[count_total.tag_a = Utf8("ffa"), count_total.ts >= TimestampMillisecond(-43199999, None), count_total.ts <= TimestampMillisecond(100000, None)] |
|
|
| | ]] |
|
|
| physical_plan | CooperativeExec |
|
|
| | MergeScanExec: REDACTED
|
|
| | |
|
|
+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
tql eval (0, 100, '1s')
|
|
max_over_time(increase(count_total{
|
|
tag_a="ffa",
|
|
}[1h])[12h:1h]);
|
|
|
|
+----+----------------------------------------------------------------------------+-------+-------+
|
|
| ts | prom_max_over_time(ts_range,prom_increase(ts_range,val,ts,Int64(3600000))) | tag_a | tag_b |
|
|
+----+----------------------------------------------------------------------------+-------+-------+
|
|
+----+----------------------------------------------------------------------------+-------+-------+
|
|
|
|
drop table count_total;
|
|
|
|
Affected Rows: 0
|
|
|