fix: preserve timestamp precision of irate (#5904)

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
Ruihang Xia
2025-04-15 23:00:30 +08:00
committed by GitHub
parent 799c7cbfa9
commit 0fb9e1995e
3 changed files with 89 additions and 3 deletions

View File

@@ -138,9 +138,7 @@ impl<const IS_RATE: bool> IDelta<IS_RATE> {
}
// else is rate
// TODO(ruihang): "divide 1000" converts the timestamp from millisecond to second.
// it should consider other percisions.
let sampled_interval = (timestamps[len - 1] - timestamps[len - 2]) / 1000;
let sampled_interval = (timestamps[len - 1] - timestamps[len - 2]) as f64 / 1000.0;
let last_value = values[len - 1];
let prev_value = values[len - 2];
let result_value = if last_value < prev_value {

View File

@@ -78,3 +78,56 @@ drop table trignan;
Affected Rows: 0
-- About irate. Related to issue https://github.com/GreptimeTeam/greptimedb/issues/5880
CREATE TABLE t(
greptime_timestamp TIMESTAMP(9) TIME INDEX,
greptime_value DOUBLE
);
Affected Rows: 0
INSERT INTO t(greptime_timestamp, greptime_value)
VALUES
('2025-04-01T00:00:00.5Z', 1),
('2025-04-01T00:00:01Z', 2),
('2025-04-01T00:00:01.5Z', 3),
('2025-04-01T00:00:02Z', 4),
('2025-04-01T00:00:02.5Z', 5),
('2025-04-01T00:00:03Z', 6),
('2025-04-01T00:00:03.5Z', 7),
('2025-04-01T00:00:04Z', 8),
('2025-04-01T00:00:04.5Z', 9),
('2025-04-01T00:00:05Z', 10),
('2025-04-01T00:00:05.5Z', 11),
('2025-04-01T00:00:06Z', 12),
('2025-04-01T00:00:06.5Z', 13),
('2025-04-01T00:00:07Z', 14),
('2025-04-01T00:00:07.5Z', 15),
('2025-04-01T00:00:08Z', 16),
('2025-04-01T00:00:08.5Z', 17),
('2025-04-01T00:00:09Z', 18),
('2025-04-01T00:00:09.5Z', 19),
('2025-04-01T00:00:10Z', 20);
Affected Rows: 20
tql eval (1743465600.5, 1743465610, '1s') irate(t[2s]);
+-------------------------+-----------------------------------------------------+
| greptime_timestamp | prom_irate(greptime_timestamp_range,greptime_value) |
+-------------------------+-----------------------------------------------------+
| 2025-04-01T00:00:01.500 | 2.0 |
| 2025-04-01T00:00:02.500 | 2.0 |
| 2025-04-01T00:00:03.500 | 2.0 |
| 2025-04-01T00:00:04.500 | 2.0 |
| 2025-04-01T00:00:05.500 | 2.0 |
| 2025-04-01T00:00:06.500 | 2.0 |
| 2025-04-01T00:00:07.500 | 2.0 |
| 2025-04-01T00:00:08.500 | 2.0 |
| 2025-04-01T00:00:09.500 | 2.0 |
+-------------------------+-----------------------------------------------------+
drop table t;
Affected Rows: 0

View File

@@ -39,3 +39,38 @@ drop table trigx;
drop table trigy;
drop table trignan;
-- About irate. Related to issue https://github.com/GreptimeTeam/greptimedb/issues/5880
CREATE TABLE t(
greptime_timestamp TIMESTAMP(9) TIME INDEX,
greptime_value DOUBLE
);
INSERT INTO t(greptime_timestamp, greptime_value)
VALUES
('2025-04-01T00:00:00.5Z', 1),
('2025-04-01T00:00:01Z', 2),
('2025-04-01T00:00:01.5Z', 3),
('2025-04-01T00:00:02Z', 4),
('2025-04-01T00:00:02.5Z', 5),
('2025-04-01T00:00:03Z', 6),
('2025-04-01T00:00:03.5Z', 7),
('2025-04-01T00:00:04Z', 8),
('2025-04-01T00:00:04.5Z', 9),
('2025-04-01T00:00:05Z', 10),
('2025-04-01T00:00:05.5Z', 11),
('2025-04-01T00:00:06Z', 12),
('2025-04-01T00:00:06.5Z', 13),
('2025-04-01T00:00:07Z', 14),
('2025-04-01T00:00:07.5Z', 15),
('2025-04-01T00:00:08Z', 16),
('2025-04-01T00:00:08.5Z', 17),
('2025-04-01T00:00:09Z', 18),
('2025-04-01T00:00:09.5Z', 19),
('2025-04-01T00:00:10Z', 20);
tql eval (1743465600.5, 1743465610, '1s') irate(t[2s]);
drop table t;