mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-09-12 16:32:16 +00:00
test(query): verify persisted AVG1 state compatibility
Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
name = "avg_state_binary"
|
||||
reason = "Verify persisted AVG1 binary states are decoded, merged, and reproduced exactly after upgrade."
|
||||
introduced_by = "PR #9035"
|
||||
topologies = ["distributed", "standalone"]
|
||||
from_range = ["*"]
|
||||
to_range = [">=v1.3.0-alpha.1"]
|
||||
features = ["table", "query", "aggregate"]
|
||||
owner = "query"
|
||||
namespace = "avg_state_binary"
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE avg1_states (
|
||||
seq_id INT PRIMARY KEY,
|
||||
state BINARY,
|
||||
ts TIMESTAMP TIME INDEX
|
||||
);
|
||||
|
||||
-- AVG1: magic (4 bytes), little-endian u64 count, little-endian f64 sum.
|
||||
INSERT INTO avg1_states (seq_id, state, ts) VALUES
|
||||
(1, X'4156473102000000000000000000000000000840', '2026-01-01 00:00:00'),
|
||||
(2, X'4156473101000000000000000000000000001840', '2026-01-01 00:00:01'),
|
||||
(3, NULL, '2026-01-01 00:00:02'),
|
||||
(4, X'4156473100000000000000000000000000000000', '2026-01-01 00:00:03');
|
||||
|
||||
ADMIN FLUSH_TABLE('avg1_states');
|
||||
@@ -0,0 +1,36 @@
|
||||
-- The persisted states have counts 2 and 1 and sums 3.0 and 6.0.
|
||||
-- Null and canonical empty states do not change the merged AVG1 state.
|
||||
SELECT avg_merge(state) = X'4156473103000000000000000000000000002240' AS merged_state_matches
|
||||
FROM avg1_states;
|
||||
|
||||
+----------------------+
|
||||
| merged_state_matches |
|
||||
+----------------------+
|
||||
| true |
|
||||
+----------------------+
|
||||
|
||||
-- A new state over the equivalent Float64 values has the exact same AVG1 bytes.
|
||||
WITH generated_values AS (
|
||||
SELECT CAST(1.0 AS DOUBLE) AS value
|
||||
UNION ALL SELECT CAST(2.0 AS DOUBLE)
|
||||
UNION ALL SELECT CAST(6.0 AS DOUBLE)
|
||||
)
|
||||
SELECT avg_state(value) = X'4156473103000000000000000000000000002240' AS generated_state_matches
|
||||
FROM generated_values;
|
||||
|
||||
+-------------------------+
|
||||
| generated_state_matches |
|
||||
+-------------------------+
|
||||
| true |
|
||||
+-------------------------+
|
||||
|
||||
-- A null-only merge is the canonical empty AVG1 state.
|
||||
SELECT avg_merge(state) = X'4156473100000000000000000000000000000000' AS null_state_is_empty
|
||||
FROM avg1_states
|
||||
WHERE state IS NULL;
|
||||
|
||||
+---------------------+
|
||||
| null_state_is_empty |
|
||||
+---------------------+
|
||||
| true |
|
||||
+---------------------+
|
||||
@@ -0,0 +1,18 @@
|
||||
-- The persisted states have counts 2 and 1 and sums 3.0 and 6.0.
|
||||
-- Null and canonical empty states do not change the merged AVG1 state.
|
||||
SELECT avg_merge(state) = X'4156473103000000000000000000000000002240' AS merged_state_matches
|
||||
FROM avg1_states;
|
||||
|
||||
-- A new state over the equivalent Float64 values has the exact same AVG1 bytes.
|
||||
WITH generated_values AS (
|
||||
SELECT CAST(1.0 AS DOUBLE) AS value
|
||||
UNION ALL SELECT CAST(2.0 AS DOUBLE)
|
||||
UNION ALL SELECT CAST(6.0 AS DOUBLE)
|
||||
)
|
||||
SELECT avg_state(value) = X'4156473103000000000000000000000000002240' AS generated_state_matches
|
||||
FROM generated_values;
|
||||
|
||||
-- A null-only merge is the canonical empty AVG1 state.
|
||||
SELECT avg_merge(state) = X'4156473100000000000000000000000000000000' AS null_state_is_empty
|
||||
FROM avg1_states
|
||||
WHERE state IS NULL;
|
||||
Reference in New Issue
Block a user