mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-14 01:02:55 +00:00
131 lines
3.5 KiB
Plaintext
131 lines
3.5 KiB
Plaintext
create table "MemAvailable" (ts timestamp time index, instance string primary key, val double);
|
|
|
|
Affected Rows: 0
|
|
|
|
create table "MemTotal" (ts timestamp time index, instance string primary key, val double);
|
|
|
|
Affected Rows: 0
|
|
|
|
insert into "MemAvailable" values
|
|
(0, 'host0', 10),
|
|
(5000, 'host0', 20),
|
|
(10000, 'host0', 30),
|
|
(0, 'host1', 40),
|
|
(5000, 'host1', 50),
|
|
(10000, 'host1', 60);
|
|
|
|
Affected Rows: 6
|
|
|
|
insert into "MemTotal" values
|
|
(0, 'host0', 100),
|
|
(5000, 'host0', 100),
|
|
(10000, 'host0', 100),
|
|
(0, 'host1', 100),
|
|
(5000, 'host1', 100),
|
|
(10000, 'host1', 100);
|
|
|
|
Affected Rows: 6
|
|
|
|
select table_name from information_schema.tables where table_type = 'BASE TABLE' order by table_id;
|
|
|
|
+--------------+
|
|
| table_name |
|
|
+--------------+
|
|
| MemAvailable |
|
|
| MemTotal |
|
|
+--------------+
|
|
|
|
-- SQLNESS SORT_RESULT 3 1
|
|
tql eval (0,10,'5s') sum(MemAvailable / 4) + sum(MemTotal / 4);
|
|
|
|
+---------------------+---------------------------------------------------------------------+
|
|
| ts | MemAvailable.sum(val / Float64(4)) + MemTotal.sum(val / Float64(4)) |
|
|
+---------------------+---------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | 62.5 |
|
|
| 1970-01-01T00:00:05 | 67.5 |
|
|
| 1970-01-01T00:00:10 | 72.5 |
|
|
+---------------------+---------------------------------------------------------------------+
|
|
|
|
drop table "MemTotal";
|
|
|
|
Affected Rows: 0
|
|
|
|
create schema "AnotherSchema";
|
|
|
|
Affected Rows: 1
|
|
|
|
create table "AnotherSchema"."MemTotal" (ts timestamp time index, instance string primary key, val double);
|
|
|
|
Affected Rows: 0
|
|
|
|
tql eval (0,10,'5s') sum(MemAvailable / 4) + sum(MemTotal / 4);
|
|
|
|
++
|
|
++
|
|
|
|
-- Cross schema is not supported
|
|
tql eval (0,10,'5s') sum(MemAvailable / 4) + sum({__name__="AnotherSchema.MemTotal"} / 4);
|
|
|
|
++
|
|
++
|
|
|
|
drop table "MemAvailable";
|
|
|
|
Affected Rows: 0
|
|
|
|
drop table "AnotherSchema"."MemTotal";
|
|
|
|
Affected Rows: 0
|
|
|
|
drop schema "AnotherSchema";
|
|
|
|
Affected Rows: 0
|
|
|
|
create table metric (ts timestamp(3) time index, `AbCdE` string primary key, val double);
|
|
|
|
Affected Rows: 0
|
|
|
|
insert into metric values
|
|
(0, 'host1', 1),
|
|
(5000, 'host1', 2),
|
|
(10000, 'host1', 3),
|
|
(0, 'host2', 4),
|
|
(5000, 'host2', 5),
|
|
(10000, 'host2', 6);
|
|
|
|
Affected Rows: 6
|
|
|
|
-- which is actually group by nothing (invalid label name)
|
|
tql eval (0,10,'5s') sum by (abcde) (metric);
|
|
|
|
+---------------------+-----------------+
|
|
| ts | sum(metric.val) |
|
|
+---------------------+-----------------+
|
|
| 1970-01-01T00:00:00 | 5.0 |
|
|
| 1970-01-01T00:00:05 | 7.0 |
|
|
| 1970-01-01T00:00:10 | 9.0 |
|
|
+---------------------+-----------------+
|
|
|
|
tql eval (0,10,'5s') sum by (AbCdE) (metric);
|
|
|
|
+-------+---------------------+-----------------+
|
|
| AbCdE | ts | sum(metric.val) |
|
|
+-------+---------------------+-----------------+
|
|
| host1 | 1970-01-01T00:00:00 | 1.0 |
|
|
| host1 | 1970-01-01T00:00:05 | 2.0 |
|
|
| host1 | 1970-01-01T00:00:10 | 3.0 |
|
|
| host2 | 1970-01-01T00:00:00 | 4.0 |
|
|
| host2 | 1970-01-01T00:00:05 | 5.0 |
|
|
| host2 | 1970-01-01T00:00:10 | 6.0 |
|
|
+-------+---------------------+-----------------+
|
|
|
|
-- not allowed by the parser
|
|
tql eval (0,10,'5s') sum by (`AbCdE`) (metric);
|
|
|
|
Error: 2000(InvalidSyntax), invalid promql query
|
|
|
|
drop table metric;
|
|
|
|
Affected Rows: 0
|
|
|