mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-16 18:22:55 +00:00
122 lines
4.5 KiB
Plaintext
122 lines
4.5 KiB
Plaintext
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
|
|
|