Skip to content

Commit

Permalink
Internal duckdb#215: MODE Frame Difference
Browse files Browse the repository at this point in the history
The frame difference loops only work if the frames overlap.
  • Loading branch information
Richard Wesley committed Sep 7, 2023
1 parent cabbc5d commit 1c2e300
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core_functions/aggregate/holistic/mode.cpp
Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions test/sql/window/test_mode_window.test
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c2e300

Please sign in to comment.