mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-03 20:02:54 +00:00
152 lines
8.6 KiB
Plaintext
152 lines
8.6 KiB
Plaintext
CREATE TABLE host (
|
|
ts timestamp(3) time index,
|
|
host STRING PRIMARY KEY,
|
|
val BIGINT,
|
|
);
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO TABLE host VALUES
|
|
("2024-01-23T22:30:00+00:00", 'host1', 0),
|
|
("2024-01-23T23:30:00+00:00", 'host1', 1),
|
|
("2024-01-24T22:30:00+00:00", 'host1', 2),
|
|
("2024-01-24T23:30:00+00:00", 'host1', 3),
|
|
("2024-01-23T22:30:00+00:00", 'host2', 4),
|
|
("2024-01-23T23:30:00+00:00", 'host2', 5),
|
|
("2024-01-24T22:30:00+00:00", 'host2', 6),
|
|
("2024-01-24T23:30:00+00:00", 'host2', 7);
|
|
|
|
Affected Rows: 8
|
|
|
|
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+------------------------+
|
|
| ts | host | min(host.val) RANGE 1d |
|
|
+---------------------+-------+------------------------+
|
|
| 2024-01-23T00:00:00 | host1 | 0 |
|
|
| 2024-01-24T00:00:00 | host1 | 2 |
|
|
| 2024-01-23T00:00:00 | host2 | 4 |
|
|
| 2024-01-24T00:00:00 | host2 | 6 |
|
|
+---------------------+-------+------------------------+
|
|
|
|
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO UNKNOWN ORDER BY host, ts;
|
|
|
|
Error: 3000(PlanQuery), Error during planning: Illegal `align to` argument `UNKNOWN` in range select query, can't be parse as NOW/CALENDAR/Timestamp, error: Failed to parse a string into Timestamp, raw string: UNKNOWN
|
|
|
|
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '1900-01-01T00:00:00+01:00' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+------------------------+
|
|
| ts | host | min(host.val) RANGE 1d |
|
|
+---------------------+-------+------------------------+
|
|
| 2024-01-22T23:00:00 | host1 | 0 |
|
|
| 2024-01-23T23:00:00 | host1 | 1 |
|
|
| 2024-01-24T23:00:00 | host1 | 3 |
|
|
| 2024-01-22T23:00:00 | host2 | 4 |
|
|
| 2024-01-23T23:00:00 | host2 | 5 |
|
|
| 2024-01-24T23:00:00 | host2 | 7 |
|
|
+---------------------+-------+------------------------+
|
|
|
|
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '2024-01-23T00:00:00+01:00' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+------------------------+
|
|
| ts | host | min(host.val) RANGE 1d |
|
|
+---------------------+-------+------------------------+
|
|
| 2024-01-22T23:00:00 | host1 | 0 |
|
|
| 2024-01-23T23:00:00 | host1 | 1 |
|
|
| 2024-01-24T23:00:00 | host1 | 3 |
|
|
| 2024-01-22T23:00:00 | host2 | 4 |
|
|
| 2024-01-23T23:00:00 | host2 | 5 |
|
|
| 2024-01-24T23:00:00 | host2 | 7 |
|
|
+---------------------+-------+------------------------+
|
|
|
|
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '2023-01-01T00:00:00+01:00' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+------------------------+
|
|
| ts | host | min(host.val) RANGE 1d |
|
|
+---------------------+-------+------------------------+
|
|
| 2024-01-22T23:00:00 | host1 | 0 |
|
|
| 2024-01-23T23:00:00 | host1 | 1 |
|
|
| 2024-01-24T23:00:00 | host1 | 3 |
|
|
| 2024-01-22T23:00:00 | host2 | 4 |
|
|
| 2024-01-23T23:00:00 | host2 | 5 |
|
|
| 2024-01-24T23:00:00 | host2 | 7 |
|
|
+---------------------+-------+------------------------+
|
|
|
|
SELECT ts, min(val) RANGE (INTERVAL '1' day) FROM host ALIGN (INTERVAL '1' day) TO '1900-01-01T00:00:00+01:00' by (1) ORDER BY ts;
|
|
|
|
+---------------------+---------------------------------------------------------------------------------------------------------+
|
|
| ts | min(host.val) RANGE IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 1, nanoseconds: 0 }") |
|
|
+---------------------+---------------------------------------------------------------------------------------------------------+
|
|
| 2024-01-22T23:00:00 | 0 |
|
|
| 2024-01-23T23:00:00 | 1 |
|
|
| 2024-01-24T23:00:00 | 3 |
|
|
+---------------------+---------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT ts, min(val) RANGE (INTERVAL '2' day - INTERVAL '1' day) FROM host ALIGN (INTERVAL '2' day - INTERVAL '1' day) TO (now() - (now() + INTERVAL '1' hour)) by (1) ORDER BY ts;
|
|
|
|
+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| ts | min(host.val) RANGE IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 2, nanoseconds: 0 }") - IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 1, nanoseconds: 0 }") |
|
|
+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2024-01-22T23:00:00 | 0 |
|
|
| 2024-01-23T23:00:00 | 1 |
|
|
| 2024-01-24T23:00:00 | 3 |
|
|
+---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
-- non-positive duration
|
|
SELECT ts, min(val) RANGE (INTERVAL '1' day - INTERVAL '2' day) FROM host ALIGN (INTERVAL '1' day) TO '1900-01-01T00:00:00+01:00' by (1) ORDER BY ts;
|
|
|
|
Error: 3000(PlanQuery), Error during planning: Illegal argument `IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 1, nanoseconds: 0 }") - IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 2, nanoseconds: 0 }")` in range select query
|
|
|
|
SELECT ts, min(val) RANGE (INTERVAL '1' day - INTERVAL '1' day) FROM host ALIGN (INTERVAL '1' day) TO '1900-01-01T00:00:00+01:00' by (1) ORDER BY ts;
|
|
|
|
Error: 3000(PlanQuery), Error during planning: Illegal argument `IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 1, nanoseconds: 0 }") - IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 1, nanoseconds: 0 }")` in range select query
|
|
|
|
-- duration not all interval
|
|
SELECT ts, min(val) RANGE (now() - INTERVAL '1' day) FROM host ALIGN (INTERVAL '1' day) TO '1900-01-01T00:00:00+01:00' by (1) ORDER BY ts;
|
|
|
|
Error: 3000(PlanQuery), Error during planning: Illegal argument `now() - IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 1, nanoseconds: 0 }")` in range select query
|
|
|
|
--- ALIGN TO with time zone ---
|
|
set time_zone='Asia/Shanghai';
|
|
|
|
Affected Rows: 0
|
|
|
|
---- align to 'Asia/Shanghai' unix epoch 0 ----
|
|
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+------------------------+
|
|
| ts | host | min(host.val) RANGE 1d |
|
|
+---------------------+-------+------------------------+
|
|
| 2024-01-23T08:00:00 | host1 | 0 |
|
|
| 2024-01-24T08:00:00 | host1 | 2 |
|
|
| 2024-01-23T08:00:00 | host2 | 4 |
|
|
| 2024-01-24T08:00:00 | host2 | 6 |
|
|
+---------------------+-------+------------------------+
|
|
|
|
set time_zone='+23:00';
|
|
|
|
Affected Rows: 0
|
|
|
|
---- align to '+23:00' unix epoch 0 ----
|
|
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts;
|
|
|
|
+---------------------+-------+------------------------+
|
|
| ts | host | min(host.val) RANGE 1d |
|
|
+---------------------+-------+------------------------+
|
|
| 2024-01-22T23:00:00 | host1 | 0 |
|
|
| 2024-01-23T23:00:00 | host1 | 1 |
|
|
| 2024-01-24T23:00:00 | host1 | 3 |
|
|
| 2024-01-22T23:00:00 | host2 | 4 |
|
|
| 2024-01-23T23:00:00 | host2 | 5 |
|
|
| 2024-01-24T23:00:00 | host2 | 7 |
|
|
+---------------------+-------+------------------------+
|
|
|
|
set time_zone='UTC';
|
|
|
|
Affected Rows: 0
|
|
|
|
DROP TABLE host;
|
|
|
|
Affected Rows: 0
|
|
|