mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2025-12-27 16:32:54 +00:00
* feat: add align to / interval support in range query * chore: fix ci * chore: simplify `parse_duration_expr` * chore: change s to ms
47 lines
2.6 KiB
Plaintext
47 lines
2.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
|
|
("1970-01-01T01:00:00+08:00", 'host1', 0),
|
|
("1970-01-01T02:00:00+08:00", 'host1', 1),
|
|
("1971-01-02T03:00:00+08:00", 'host1', 2),
|
|
("1971-01-02T04:00:00+08:00", 'host1', 3),
|
|
("1970-01-01T01:00:00+08:00", 'host2', 4),
|
|
("1970-01-01T02:00:00+08:00", 'host2', 5),
|
|
("1971-01-02T03:00:00+08:00", 'host2', 6),
|
|
("1971-01-02T04:00:00+08:00", 'host2', 7);
|
|
|
|
Affected Rows: 8
|
|
|
|
SELECT ts, host, min(val) RANGE (INTERVAL '1 year') FROM host ALIGN (INTERVAL '1 year') ORDER BY host, ts;
|
|
|
|
+---------------------+-------+--------------------------------------------------------------------------------------+
|
|
| ts | host | MIN(host.val) RANGE IntervalMonthDayNano("950737950171172051122527404032") FILL NULL |
|
|
+---------------------+-------+--------------------------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 0 |
|
|
| 1971-12-22T00:00:00 | host1 | 2 |
|
|
| 1970-01-01T00:00:00 | host2 | 4 |
|
|
| 1971-12-22T00:00:00 | host2 | 6 |
|
|
+---------------------+-------+--------------------------------------------------------------------------------------+
|
|
|
|
SELECT ts, host, min(val) RANGE (INTERVAL '1' year) FROM host ALIGN (INTERVAL '1' year) ORDER BY host, ts;
|
|
|
|
+---------------------+-------+--------------------------------------------------------------------------------------+
|
|
| ts | host | MIN(host.val) RANGE IntervalMonthDayNano("950737950171172051122527404032") FILL NULL |
|
|
+---------------------+-------+--------------------------------------------------------------------------------------+
|
|
| 1970-01-01T00:00:00 | host1 | 0 |
|
|
| 1971-12-22T00:00:00 | host1 | 2 |
|
|
| 1970-01-01T00:00:00 | host2 | 4 |
|
|
| 1971-12-22T00:00:00 | host2 | 6 |
|
|
+---------------------+-------+--------------------------------------------------------------------------------------+
|
|
|
|
DROP TABLE host;
|
|
|
|
Affected Rows: 0
|
|
|