From 87be1cc32366836852ce666f33e4e4958f346406 Mon Sep 17 00:00:00 2001 From: discord9 Date: Mon, 7 Sep 2026 17:21:33 +0800 Subject: [PATCH] test(query): verify persisted AVG1 state compatibility Signed-off-by: discord9 --- .../cases/avg_state_binary/case.toml | 9 +++++ .../cases/avg_state_binary/setup.sql | 14 ++++++++ .../cases/avg_state_binary/verify.result | 36 +++++++++++++++++++ .../cases/avg_state_binary/verify.sql | 18 ++++++++++ 4 files changed, 77 insertions(+) create mode 100644 tests/compatibility/cases/avg_state_binary/case.toml create mode 100644 tests/compatibility/cases/avg_state_binary/setup.sql create mode 100644 tests/compatibility/cases/avg_state_binary/verify.result create mode 100644 tests/compatibility/cases/avg_state_binary/verify.sql diff --git a/tests/compatibility/cases/avg_state_binary/case.toml b/tests/compatibility/cases/avg_state_binary/case.toml new file mode 100644 index 0000000000..51c9d4ff26 --- /dev/null +++ b/tests/compatibility/cases/avg_state_binary/case.toml @@ -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" diff --git a/tests/compatibility/cases/avg_state_binary/setup.sql b/tests/compatibility/cases/avg_state_binary/setup.sql new file mode 100644 index 0000000000..2bb2db577e --- /dev/null +++ b/tests/compatibility/cases/avg_state_binary/setup.sql @@ -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'); diff --git a/tests/compatibility/cases/avg_state_binary/verify.result b/tests/compatibility/cases/avg_state_binary/verify.result new file mode 100644 index 0000000000..c3eba781a4 --- /dev/null +++ b/tests/compatibility/cases/avg_state_binary/verify.result @@ -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 | ++---------------------+ diff --git a/tests/compatibility/cases/avg_state_binary/verify.sql b/tests/compatibility/cases/avg_state_binary/verify.sql new file mode 100644 index 0000000000..30cade275b --- /dev/null +++ b/tests/compatibility/cases/avg_state_binary/verify.sql @@ -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;