Compare commits

...

2 Commits

Author SHA1 Message Date
Yakov Olkhovskiy
86086133f8
Merge pull request #69735 from ClickHouse/backport/24.8/68262
Backport #68262 to 24.8: Fix crash in lag/lead
2024-09-18 22:19:16 -04:00
robot-clickhouse
6a5bf90f5d Backport #68262 to 24.8: Fix crash in lag/lead 2024-09-18 15:12:43 +00:00
3 changed files with 37 additions and 2 deletions

View File

@ -1157,8 +1157,7 @@ void WindowTransform::appendChunk(Chunk & chunk)
// Initialize output columns.
for (auto & ws : workspaces)
{
if (ws.window_function_impl)
block.casted_columns.push_back(ws.window_function_impl->castColumn(block.input_columns, ws.argument_column_indices));
block.casted_columns.push_back(ws.window_function_impl ? ws.window_function_impl->castColumn(block.input_columns, ws.argument_column_indices) : nullptr);
block.output_columns.push_back(ws.aggregate_function->getResultType()
->createColumn());

View File

@ -38,3 +38,19 @@
7
8
9
15 \N 3 15 15 15 15
14 \N 2 10 10 10 154
13 \N 2 10 10 10 143
12 \N 2 10 10 10 14
11 \N 2 10 10 10 12
10 \N 2 10 10 10 10
9 \N 1 5 5 5 99
8 \N 1 5 5 5 88
7 \N 1 5 5 5 9
6 \N 1 5 5 5 7
5 \N 1 5 5 5 5
4 \N 0 0 0 0 44
3 \N 0 0 0 0 33
2 \N 0 0 0 0 4
1 \N 0 0 0 0 2
0 \N 0 0 0 0 0

View File

@ -2,3 +2,23 @@ SELECT lagInFrame(2::UInt128, 2, number) OVER w FROM numbers(10) WINDOW w AS (OR
SELECT leadInFrame(2::UInt128, 2, number) OVER w FROM numbers(10) WINDOW w AS (ORDER BY number);
SELECT lagInFrame(2::UInt64, 2, number) OVER w FROM numbers(10) WINDOW w AS (ORDER BY number);
SELECT leadInFrame(2::UInt64, 2, number) OVER w FROM numbers(10) WINDOW w AS (ORDER BY number);
SELECT
number,
YYYYMMDDToDate(1, toLowCardinality(11), max(YYYYMMDDToDate(YYYYMMDDToDate(toLowCardinality(1), 11, materialize(NULL), 19700101.1, 1, 27, 7, materialize(toUInt256(37)), 9, 19, 9), 1, toUInt128(11), NULL, 19700101.1, 1, 27, 7, 37, 9, 19, 9), toUInt256(30)) IGNORE NULLS OVER w, NULL, 19700101.1, toNullable(1), 27, materialize(7), 37, 9, 19, 9),
p,
pp,
lagInFrame(number, number - pp) OVER w AS lag2,
lagInFrame(number, number - pp, number * 11) OVER w AS lag,
leadInFrame(number, number - pp, number * 11) OVER w AS lead
FROM
(
SELECT
number,
intDiv(number, 5) AS p,
p * 5 AS pp
FROM numbers(16)
)
WHERE toLowCardinality(1)
WINDOW w AS (PARTITION BY p ORDER BY number ASC NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)
ORDER BY number DESC NULLS LAST;