Files
greptimedb/tests/cases/standalone/common/range/to.result
2024-03-13 09:20:34 +00:00

128 lines
5.5 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), DataFusion error: 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("18446744073709551616") |
+---------------------+------------------------------------------------------------------+
| 2024-01-22T23:00:00 | 0 |
| 2024-01-23T23:00:00 | 1 |
| 2024-01-24T23:00:00 | 3 |
+---------------------+------------------------------------------------------------------+
--- 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