-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support any precision in PromQL (#3933)
* feat: support any precision in PromQL * chore: add test
- Loading branch information
1 parent
c915916
commit 9f4a6c6
Showing
7 changed files
with
355 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
CREATE TABLE host_sec ( | ||
ts timestamp(0) time index, | ||
host STRING PRIMARY KEY, | ||
val DOUBLE, | ||
); | ||
|
||
Affected Rows: 0 | ||
|
||
INSERT INTO TABLE host_sec VALUES | ||
(0, 'host1', 1), | ||
(0, 'host2', 2), | ||
(5, 'host1', 3), | ||
(5, 'host2', 4), | ||
(10, 'host1', 5), | ||
(10, 'host2', 6), | ||
(15, 'host1', 7), | ||
(15, 'host2', 8); | ||
|
||
Affected Rows: 8 | ||
|
||
CREATE TABLE host_micro ( | ||
ts timestamp(6) time index, | ||
host STRING PRIMARY KEY, | ||
val DOUBLE, | ||
); | ||
|
||
Affected Rows: 0 | ||
|
||
INSERT INTO TABLE host_micro VALUES | ||
(0, 'host1', 1), | ||
(0, 'host2', 2), | ||
(5000000, 'host1', 3), | ||
(5000000, 'host2', 4), | ||
(10000000, 'host1', 5), | ||
(10000000, 'host2', 6), | ||
(15000000, 'host1', 7), | ||
(15000000, 'host2', 8); | ||
|
||
Affected Rows: 8 | ||
|
||
-- Test on Timestamps of different precisions | ||
-- SQLNESS SORT_RESULT 3 1 | ||
TQL EVAL (0, 15, '5s') host_sec{host="host1"}; | ||
|
||
+-----+-------+---------------------+ | ||
| val | host | ts | | ||
+-----+-------+---------------------+ | ||
| 1.0 | host1 | 1970-01-01T00:00:00 | | ||
| 3.0 | host1 | 1970-01-01T00:00:05 | | ||
| 5.0 | host1 | 1970-01-01T00:00:10 | | ||
| 7.0 | host1 | 1970-01-01T00:00:15 | | ||
+-----+-------+---------------------+ | ||
|
||
-- SQLNESS SORT_RESULT 3 1 | ||
TQL EVAL (0, 15, '5s') avg_over_time(host_sec{host="host1"}[5s]); | ||
|
||
+---------------------+----------------------------------+-------+ | ||
| ts | prom_avg_over_time(ts_range,val) | host | | ||
+---------------------+----------------------------------+-------+ | ||
| 1970-01-01T00:00:00 | 1.0 | host1 | | ||
| 1970-01-01T00:00:05 | 2.0 | host1 | | ||
| 1970-01-01T00:00:10 | 4.0 | host1 | | ||
| 1970-01-01T00:00:15 | 6.0 | host1 | | ||
+---------------------+----------------------------------+-------+ | ||
|
||
-- SQLNESS SORT_RESULT 3 1 | ||
TQL EVAL (0, 15, '5s') host_micro{host="host1"}; | ||
|
||
+-----+-------+---------------------+ | ||
| val | host | ts | | ||
+-----+-------+---------------------+ | ||
| 1.0 | host1 | 1970-01-01T00:00:00 | | ||
| 3.0 | host1 | 1970-01-01T00:00:05 | | ||
| 5.0 | host1 | 1970-01-01T00:00:10 | | ||
| 7.0 | host1 | 1970-01-01T00:00:15 | | ||
+-----+-------+---------------------+ | ||
|
||
-- SQLNESS SORT_RESULT 3 1 | ||
TQL EVAL (0, 15, '5s') avg_over_time(host_micro{host="host1"}[5s]); | ||
|
||
+---------------------+----------------------------------+-------+ | ||
| ts | prom_avg_over_time(ts_range,val) | host | | ||
+---------------------+----------------------------------+-------+ | ||
| 1970-01-01T00:00:00 | 1.0 | host1 | | ||
| 1970-01-01T00:00:05 | 2.0 | host1 | | ||
| 1970-01-01T00:00:10 | 4.0 | host1 | | ||
| 1970-01-01T00:00:15 | 6.0 | host1 | | ||
+---------------------+----------------------------------+-------+ | ||
|
||
-- SQLNESS SORT_RESULT 3 1 | ||
TQL EVAL (0, 15, '5s') host_sec{host="host1"} + host_micro{host="host1"}; | ||
|
||
+-------+---------------------+-------------------------------+ | ||
| host | ts | host_sec.val + host_micro.val | | ||
+-------+---------------------+-------------------------------+ | ||
| host1 | 1970-01-01T00:00:00 | 2.0 | | ||
| host1 | 1970-01-01T00:00:05 | 6.0 | | ||
| host1 | 1970-01-01T00:00:10 | 10.0 | | ||
| host1 | 1970-01-01T00:00:15 | 14.0 | | ||
+-------+---------------------+-------------------------------+ | ||
|
||
-- SQLNESS SORT_RESULT 3 1 | ||
TQL EVAL (0, 15, '5s') avg_over_time(host_sec{host="host1"}[5s]) + avg_over_time(host_micro{host="host1"}[5s]); | ||
|
||
+-------+---------------------+-----------------------------------------------------------------------------------------+ | ||
| host | ts | host_sec.prom_avg_over_time(ts_range,val) + host_micro.prom_avg_over_time(ts_range,val) | | ||
+-------+---------------------+-----------------------------------------------------------------------------------------+ | ||
| host1 | 1970-01-01T00:00:00 | 2.0 | | ||
| host1 | 1970-01-01T00:00:05 | 4.0 | | ||
| host1 | 1970-01-01T00:00:10 | 8.0 | | ||
| host1 | 1970-01-01T00:00:15 | 12.0 | | ||
+-------+---------------------+-----------------------------------------------------------------------------------------+ | ||
|
||
DROP TABLE host_sec; | ||
|
||
Affected Rows: 0 | ||
|
||
DROP TABLE host_micro; | ||
|
||
Affected Rows: 0 | ||
|
Oops, something went wrong.