mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-09 14:52:58 +00:00
fix: preserve timestamp precision of irate (#5904)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user