From 1c2e300dea1e396226ecbef56479c8ba634e9159 Mon Sep 17 00:00:00 2001 From: Richard Wesley Date: Thu, 7 Sep 2023 15:57:39 +1200 Subject: [PATCH] Internal #215: MODE Frame Difference The frame difference loops only work if the frames overlap. --- src/core_functions/aggregate/holistic/mode.cpp | 2 +- test/sql/window/test_mode_window.test | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/core_functions/aggregate/holistic/mode.cpp b/src/core_functions/aggregate/holistic/mode.cpp index ea5be91131b..0f81b88c920 100644 --- a/src/core_functions/aggregate/holistic/mode.cpp +++ b/src/core_functions/aggregate/holistic/mode.cpp @@ -220,7 +220,7 @@ struct ModeFunction { state.frequency_map = new typename STATE::Counts; } const double tau = .25; - if (state.nonzero <= tau * state.frequency_map->size()) { + if (state.nonzero <= tau * state.frequency_map->size() || prev.end <= frame.start || frame.end <= prev.start) { state.Reset(); // for f ∈ F do for (auto f = frame.start; f < frame.end; ++f) { diff --git a/test/sql/window/test_mode_window.test b/test/sql/window/test_mode_window.test index 8306043687d..4e2df25f2c8 100644 --- a/test/sql/window/test_mode_window.test +++ b/test/sql/window/test_mode_window.test @@ -2,9 +2,6 @@ # description: Test MODE aggregate as a window function # group: [window] -# Temporary fix until state issue resolved -require vector_size 64 - statement ok SET default_null_order='nulls_first'; @@ -93,7 +90,7 @@ NULL NULL NULL NULL query III SELECT r, n, mode(n) over (order by r rows between 1 preceding and 1 following) FROM (SELECT r, CASE r % 2 WHEN 0 THEN r ELSE NULL END AS n FROM modes) nulls -ORDER BY 1 +ORDER BY ALL ---- NULL NULL NULL NULL NULL NULL @@ -158,7 +155,9 @@ PRAGMA debug_window_mode=${windowmode} query III WITH t(r) AS (VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (NULL), (NULL), (NULL)) -SELECT r, r//3, mode(r//3) over (order by r rows between 1 preceding and 1 following) FROM t ORDER BY 1, 2 +SELECT r, r//3, mode(r//3) over (order by r rows between 1 preceding and 1 following) +FROM t +ORDER BY ALL ---- NULL NULL NULL NULL NULL NULL