Skip to content

Commit

Permalink
Merge pull request ClickHouse#55905 from ClickHouse/backport/23.7/55895
Browse files Browse the repository at this point in the history
Backport ClickHouse#55895 to 23.7: Fix window functions in case of sparse columns.
  • Loading branch information
alexey-milovidov authored Oct 21, 2023
2 parents fb0924f + 5553c23 commit 6b047a4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Processors/Transforms/WindowTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ void WindowTransform::appendChunk(Chunk & chunk)
auto columns = chunk.detachColumns();
block.original_input_columns = columns;
for (auto & column : columns)
column = recursiveRemoveLowCardinality(std::move(column)->convertToFullColumnIfConst());
column = recursiveRemoveLowCardinality(std::move(column)->convertToFullColumnIfConst()->convertToFullColumnIfSparse());
block.input_columns = std::move(columns);

// Initialize output columns.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
false
false
false


Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- https://github.com/ClickHouse/ClickHouse/issues/55843
-- These tests pass without the fix when either of
-- - optimize_read_in_window_order = 0 and optimize_read_in_order = 0
-- - ratio_of_defaults_for_sparse_serialization = 1
-- However it is better to leave the settings as randomized because we run
-- stateless tests quite a few times during a PR, so if a bug is introduced
-- then there is a big chance of catching it. Furthermore, randomized settings
-- might identify new bugs.

CREATE TABLE test1
(
id String,
time DateTime64(9),
key Int64,
value Bool,
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(time)
ORDER BY (key, id, time);

INSERT INTO test1 VALUES ('id0', now(), 3, false)

SELECT last_value(value) OVER (PARTITION BY id ORDER BY time ASC) as last_value
FROM test1
WHERE (key = 3);

SELECT last_value(value) OVER (ORDER BY time ASC) as last_value
FROM test1
WHERE (key = 3);

SELECT last_value(value) OVER (PARTITION BY id ORDER BY time ASC) as last_value
FROM test1;



CREATE TABLE test2
(
time DateTime,
value String
)
ENGINE = MergeTree
ORDER BY (time) AS SELECT 0, '';

SELECT any(value) OVER (ORDER BY time ASC) FROM test2;
SELECT last_value(value) OVER (ORDER BY time ASC) FROM test2;

0 comments on commit 6b047a4

Please sign in to comment.