Files
greptimedb/tests/cases/standalone/common/range/to.result
WU Jingdi 806400caff feat: add align to / interval support in range query (#2842)
* feat: add align to / interval support in range query

* chore: fix ci

* chore: simplify `parse_duration_expr`

* chore: change s to ms
2023-12-04 08:00:41 +00:00

100 lines
5.2 KiB
Plaintext

CREATE TABLE host (
ts timestamp(3) time index,
host STRING PRIMARY KEY,
val BIGINT,
);
Affected Rows: 0
INSERT INTO TABLE host VALUES
("1970-01-01T23:30:00+00:00", 'host1', 0),
("1970-01-01T22:30:00+00:00", 'host1', 1),
("1970-01-02T23:30:00+00:00", 'host1', 2),
("1970-01-02T22:30:00+00:00", 'host1', 3),
("1970-01-01T23:30:00+00:00", 'host2', 4),
("1970-01-01T22:30:00+00:00", 'host2', 5),
("1970-01-02T23:30:00+00:00", 'host2', 6),
("1970-01-02T22: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 FILL NULL |
+---------------------+-------+----------------------------------+
| 1970-01-02T00:00:00 | host1 | 0 |
| 1970-01-03T00:00:00 | host1 | 2 |
| 1970-01-02T00:00:00 | host2 | 4 |
| 1970-01-03T00:00:00 | host2 | 6 |
+---------------------+-------+----------------------------------+
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO CALENDAR ORDER BY host, ts;
+---------------------+-------+----------------------------------+
| ts | host | MIN(host.val) RANGE 1d FILL NULL |
+---------------------+-------+----------------------------------+
| 1970-01-02T00:00:00 | host1 | 0 |
| 1970-01-03T00:00:00 | host1 | 2 |
| 1970-01-02T00:00:00 | host2 | 4 |
| 1970-01-03T00: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 FILL NULL |
+---------------------+-------+----------------------------------+
| 1970-01-01T23:00:00 | host1 | 1 |
| 1970-01-02T23:00:00 | host1 | 0 |
| 1970-01-03T23:00:00 | host1 | 2 |
| 1970-01-01T23:00:00 | host2 | 5 |
| 1970-01-02T23:00:00 | host2 | 4 |
| 1970-01-03T23:00:00 | host2 | 6 |
+---------------------+-------+----------------------------------+
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '1970-01-01T00:00:00+01:00' ORDER BY host, ts;
+---------------------+-------+----------------------------------+
| ts | host | MIN(host.val) RANGE 1d FILL NULL |
+---------------------+-------+----------------------------------+
| 1970-01-01T23:00:00 | host1 | 1 |
| 1970-01-02T23:00:00 | host1 | 0 |
| 1970-01-03T23:00:00 | host1 | 2 |
| 1970-01-01T23:00:00 | host2 | 5 |
| 1970-01-02T23:00:00 | host2 | 4 |
| 1970-01-03T23:00:00 | host2 | 6 |
+---------------------+-------+----------------------------------+
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 FILL NULL |
+---------------------+-------+----------------------------------+
| 1970-01-01T23:00:00 | host1 | 1 |
| 1970-01-02T23:00:00 | host1 | 0 |
| 1970-01-03T23:00:00 | host1 | 2 |
| 1970-01-01T23:00:00 | host2 | 5 |
| 1970-01-02T23:00:00 | host2 | 4 |
| 1970-01-03T23:00:00 | host2 | 6 |
+---------------------+-------+----------------------------------+
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") FILL NULL |
+---------------------+----------------------------------------------------------------------------+
| 1970-01-01T23:00:00 | 1 |
| 1970-01-02T23:00:00 | 0 |
| 1970-01-03T23:00:00 | 2 |
+---------------------+----------------------------------------------------------------------------+
DROP TABLE host;
Affected Rows: 0