-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(promql): supports sort, sort_desc etc. functions (#5542)
* feat(promql): supports sort, sort_desc etc. functions * chore: fix toml format and tests * chore: update deps Co-authored-by: Weny Xu <[email protected]> * chore: remove fixme * fix: cargo lock * chore: style --------- Co-authored-by: Weny Xu <[email protected]>
- Loading branch information
1 parent
c8bdeaa
commit 62a8b8b
Showing
5 changed files
with
270 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,154 @@ | ||
CREATE TABLE test ( | ||
ts timestamp(3) time index, | ||
host STRING, | ||
idc STRING, | ||
val BIGINT, | ||
PRIMARY KEY(host, idc), | ||
); | ||
|
||
Affected Rows: 0 | ||
|
||
INSERT INTO TABLE test VALUES | ||
(0, 'host1', 'idc1', 1), | ||
(0, 'host2', 'idc1', 2), | ||
(5000, 'host1', 'idc2', 3), | ||
(5000, 'host2', 'idc2', 4), | ||
(10000, 'host1', 'idc3', 5), | ||
(10000, 'host2', 'idc3', 6), | ||
(15000, 'host1', 'idc4', 7), | ||
(15000, 'host2', 'idc4', 8); | ||
|
||
Affected Rows: 8 | ||
|
||
TQL EVAL (0, 15, '5s') sort(test{host="host1"}); | ||
|
||
+---------------------+-----+-------+------+ | ||
| ts | val | host | idc | | ||
+---------------------+-----+-------+------+ | ||
| 1970-01-01T00:00:00 | 1 | host1 | idc1 | | ||
| 1970-01-01T00:00:05 | 1 | host1 | idc1 | | ||
| 1970-01-01T00:00:10 | 1 | host1 | idc1 | | ||
| 1970-01-01T00:00:15 | 1 | host1 | idc1 | | ||
| 1970-01-01T00:00:05 | 3 | host1 | idc2 | | ||
| 1970-01-01T00:00:10 | 3 | host1 | idc2 | | ||
| 1970-01-01T00:00:15 | 3 | host1 | idc2 | | ||
| 1970-01-01T00:00:10 | 5 | host1 | idc3 | | ||
| 1970-01-01T00:00:15 | 5 | host1 | idc3 | | ||
| 1970-01-01T00:00:15 | 7 | host1 | idc4 | | ||
+---------------------+-----+-------+------+ | ||
|
||
TQL EVAL (0, 15, '5s') sort_desc(test{host="host1"}); | ||
|
||
+---------------------+-----+-------+------+ | ||
| ts | val | host | idc | | ||
+---------------------+-----+-------+------+ | ||
| 1970-01-01T00:00:15 | 7 | host1 | idc4 | | ||
| 1970-01-01T00:00:10 | 5 | host1 | idc3 | | ||
| 1970-01-01T00:00:15 | 5 | host1 | idc3 | | ||
| 1970-01-01T00:00:05 | 3 | host1 | idc2 | | ||
| 1970-01-01T00:00:10 | 3 | host1 | idc2 | | ||
| 1970-01-01T00:00:15 | 3 | host1 | idc2 | | ||
| 1970-01-01T00:00:00 | 1 | host1 | idc1 | | ||
| 1970-01-01T00:00:05 | 1 | host1 | idc1 | | ||
| 1970-01-01T00:00:10 | 1 | host1 | idc1 | | ||
| 1970-01-01T00:00:15 | 1 | host1 | idc1 | | ||
+---------------------+-----+-------+------+ | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
TQL EVAL (0, 15, '5s') sort(sum(test{host="host2"}) by (idc)); | ||
|
||
+---------------------+---------------+------+ | ||
| ts | sum(test.val) | idc | | ||
+---------------------+---------------+------+ | ||
|timestamp | 2 | idc1 | | ||
|timestamp | 2 | idc1 | | ||
|timestamp | 2 | idc1 | | ||
|timestamp | 2 | idc1 | | ||
|timestamp | 4 | idc2 | | ||
|timestamp | 4 | idc2 | | ||
|timestamp | 4 | idc2 | | ||
|timestamp | 6 | idc3 | | ||
|timestamp | 6 | idc3 | | ||
|timestamp | 8 | idc4 | | ||
+---------------------+---------------+------+ | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
TQL EVAL (0, 15, '5s') sort_desc(sum(test{host="host2"}) by (idc)); | ||
|
||
+---------------------+---------------+------+ | ||
| ts | sum(test.val) | idc | | ||
+---------------------+---------------+------+ | ||
|timestamp | 8 | idc4 | | ||
|timestamp | 6 | idc3 | | ||
|timestamp | 6 | idc3 | | ||
|timestamp | 4 | idc2 | | ||
|timestamp | 4 | idc2 | | ||
|timestamp | 4 | idc2 | | ||
|timestamp | 2 | idc1 | | ||
|timestamp | 2 | idc1 | | ||
|timestamp | 2 | idc1 | | ||
|timestamp | 2 | idc1 | | ||
+---------------------+---------------+------+ | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
-- SQLNESS REPLACE (\s\d\s) val | ||
TQL EVAL (0, 15, '5s') sort_by_label(sum(test) by (idc, host), "idc", "host"); | ||
|
||
+---------------------+---------------+------+-------+ | ||
| ts | sum(test.val) | idc | host | | ||
+---------------------+---------------+------+-------+ | ||
|timestamp |val | idc1 | host1 | | ||
|timestamp |val | idc1 | host1 | | ||
|timestamp |val | idc1 | host1 | | ||
|timestamp |val | idc1 | host1 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc2 | host1 | | ||
|timestamp |val | idc2 | host1 | | ||
|timestamp |val | idc2 | host1 | | ||
|timestamp |val | idc2 | host2 | | ||
|timestamp |val | idc2 | host2 | | ||
|timestamp |val | idc2 | host2 | | ||
|timestamp |val | idc3 | host1 | | ||
|timestamp |val | idc3 | host1 | | ||
|timestamp |val | idc3 | host2 | | ||
|timestamp |val | idc3 | host2 | | ||
|timestamp |val | idc4 | host1 | | ||
|timestamp |val | idc4 | host2 | | ||
+---------------------+---------------+------+-------+ | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
-- SQLNESS REPLACE (\s\d\s) val | ||
TQL EVAL (0, 15, '5s') sort_by_label_desc(sum(test) by (idc, host), "idc", "host"); | ||
|
||
+---------------------+---------------+------+-------+ | ||
| ts | sum(test.val) | idc | host | | ||
+---------------------+---------------+------+-------+ | ||
|timestamp |val | idc4 | host2 | | ||
|timestamp |val | idc4 | host1 | | ||
|timestamp |val | idc3 | host2 | | ||
|timestamp |val | idc3 | host2 | | ||
|timestamp |val | idc3 | host1 | | ||
|timestamp |val | idc3 | host1 | | ||
|timestamp |val | idc2 | host2 | | ||
|timestamp |val | idc2 | host2 | | ||
|timestamp |val | idc2 | host2 | | ||
|timestamp |val | idc2 | host1 | | ||
|timestamp |val | idc2 | host1 | | ||
|timestamp |val | idc2 | host1 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc1 | host2 | | ||
|timestamp |val | idc1 | host1 | | ||
|timestamp |val | idc1 | host1 | | ||
|timestamp |val | idc1 | host1 | | ||
|timestamp |val | idc1 | host1 | | ||
+---------------------+---------------+------+-------+ | ||
|
||
drop table test; | ||
|
||
Affected Rows: 0 | ||
|
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,38 @@ | ||
CREATE TABLE test ( | ||
ts timestamp(3) time index, | ||
host STRING, | ||
idc STRING, | ||
val BIGINT, | ||
PRIMARY KEY(host, idc), | ||
); | ||
|
||
INSERT INTO TABLE test VALUES | ||
(0, 'host1', 'idc1', 1), | ||
(0, 'host2', 'idc1', 2), | ||
(5000, 'host1', 'idc2', 3), | ||
(5000, 'host2', 'idc2', 4), | ||
(10000, 'host1', 'idc3', 5), | ||
(10000, 'host2', 'idc3', 6), | ||
(15000, 'host1', 'idc4', 7), | ||
(15000, 'host2', 'idc4', 8); | ||
|
||
|
||
TQL EVAL (0, 15, '5s') sort(test{host="host1"}); | ||
|
||
TQL EVAL (0, 15, '5s') sort_desc(test{host="host1"}); | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
TQL EVAL (0, 15, '5s') sort(sum(test{host="host2"}) by (idc)); | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
TQL EVAL (0, 15, '5s') sort_desc(sum(test{host="host2"}) by (idc)); | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
-- SQLNESS REPLACE (\s\d\s) val | ||
TQL EVAL (0, 15, '5s') sort_by_label(sum(test) by (idc, host), "idc", "host"); | ||
|
||
-- SQLNESS REPLACE (\s1970-01-01T\d\d:\d\d:\d\d) timestamp | ||
-- SQLNESS REPLACE (\s\d\s) val | ||
TQL EVAL (0, 15, '5s') sort_by_label_desc(sum(test) by (idc, host), "idc", "host"); | ||
|
||
drop table test; |